0003-content-analysis-cleanup.patch

guillomovitch, 01/02/2015 12:52 AM

Download (7.84 KB)

View differences:

inc/dell.class.php
73 73
      return $info;
74 74
   }
75 75
   
76
   function getSearchField() {
77
      
78
      return false;
79
   }
80

  
81 76
}
82 77

  
83 78
?>
inc/postimport.class.php
179 179

  
180 180
   static function importDate($suppliername,$contents) {
181 181
         
182
      if ($suppliername=="Dell") {//dell : 2008-09-03T00:00:00
183
         
184
         $maDate = PluginManufacturersimportsDellSoap::getDates($contents, "StartDate");
185
         
186
      } else {
187
         
188
         $supplierclass = "PluginManufacturersimports".$suppliername;
189
         $supplier = new $supplierclass();
190
         $maDate = $supplier->getBuyDate($contents);
191

  
192
      }
182
      $supplierclass = "PluginManufacturersimports".$suppliername;
183
      $supplier = new $supplierclass();
184
      $maDate = $supplier->getBuyDate($contents);
193 185

  
194 186
      return $maDate;
195 187
   }
196 188

  
197
   static function importWarranty($suppliername,$maDate,$contents,$warranty) {
189
   static function importDateFin($suppliername,$contents) {
198 190
      
199
      if ($warranty==0) {
200
         if ($suppliername=="Dell") {
201
            
202
            $maDateFin = PluginManufacturersimportsDellSoap::getDates($contents, "EndDate");
203

  
204
         } else {
205
         
206
            $supplierclass = "PluginManufacturersimports".$suppliername;
207
            $supplier = new $supplierclass();
208
            $maDateFin = $supplier->getExpirationDate($contents);
209

  
210
         }
211
         
212
         if ($maDateFin != "0000-00-00") {
213
            list ($adebut, $mdebut, $jdebut) = explode ('-', $maDate);
214
            list ($afin, $mfin, $jfin) = explode ('-', $maDateFin);
215

  
216
            $warranty = 0;
217
            $warranty = 12 - $mdebut;
218
            for ($year = $adebut + 1; $year < $afin;$year++) {
219
               $warranty += 12;
220
            }
221
            $warranty += $mfin;
222
         }
223
      }
191
      $supplierclass = "PluginManufacturersimports".$suppliername;
192
      $supplier = new $supplierclass();
193
      $maDateFin = $supplier->getExpirationDate($contents);
224 194
      
225
      return $warranty;
195
      return $maDateFin;
226 196
  }
227 197
  
228 198
   /**
......
307 277

  
308 278
         $contents = self::cURLData($options);
309 279
         
310
         // On extrait la date de garantie de la variable contents.
311
         $field=self::selectSupplierfield ($suppliername);
312
         
313
         if ($suppliername=="Dell"
314
               || ($suppliername!="Dell"
315
                  && !stristr($contents, $field) === FALSE)) {
316
         
317
            if ($suppliername!="Dell") {
318
               $finduhtml = stristr($contents, $field);
280
         if ($suppliername=="Dell") {
281
            $maDate    = PluginManufacturersimportsDellSoap::getDates($compSerial, "StartDate");
282
            $maDateFin = PluginManufacturersimportsDellSoap::getDates($compSerial, "EndDate");
283
         } else {
284
            // On extrait la date de garantie de la variable contents.
285
            $field=self::selectSupplierfield ($suppliername);
286
            $finduhtml = stristr($contents, $field);
287
            if (!$finduhtml === FALSE) {
288
               $maDate    = self::importDate($suppliername,$finduhtml);
289
               $maDateFin = self::importDateFin($suppliername,$finduhtml);
319 290
            } else {
320
               $finduhtml = $compSerial;
321
               $contents = $compSerial;
291
               self::isInError($type,$ID);
322 292
            }
323
            $maDate = self::importDate($suppliername,$finduhtml);
293
         }
324 294

  
325
            $warranty = self::importWarranty($suppliername,$maDate,$contents,$warranty);
295
         if ($maDateFin != "0000-00-00") {
296
            list ($adebut, $mdebut, $jdebut) = explode ('-', $maDate);
297
            list ($afin, $mfin, $jfin) = explode ('-', $maDateFin);
326 298

  
327
            if ($maDate!="0000-00-00") {
328
               //warranty for life
329
               if ($warranty > 120) {
330
                  $warranty=-1;
331
               }
299
            $warranty = 0;
300
            $warranty = 12 - $mdebut;
301
            for ($year = $adebut + 1; $year < $afin;$year++) {
302
               $warranty += 12;
303
            }
304
            $warranty += $mfin;
305
         }
332 306

  
333
               $date=date("Y-m-d");
334
               $options = array ("itemtype" => $type,
335
                  "ID" => $ID,
336
                  "date" => $date,
337
                  "supplierId" => $supplierId,
338
                  "warranty" => $warranty,
339
                  "suppliername" => $suppliername,
340
                  "addcomments" => $addcomments,
341
                  "maDate" => $maDate);
342
               self::saveInfocoms ($options);
307
         if ($maDate!="0000-00-00") {
308
            //warranty for life
309
            if ($warranty > 120) {
310
               $warranty=-1;
311
            }
343 312

  
344
               // on cree un doc dans GLPI qu'on va lier au materiel
313
            $date=date("Y-m-d");
314
            $options = array ("itemtype" => $type,
315
               "ID" => $ID,
316
               "date" => $date,
317
               "supplierId" => $supplierId,
318
               "warranty" => $warranty,
319
               "suppliername" => $suppliername,
320
               "addcomments" => $addcomments,
321
               "maDate" => $maDate);
322
            self::saveInfocoms ($options);
345 323

  
346
               if ($adddoc!=0 && $suppliername!="Dell") {
324
            // on cree un doc dans GLPI qu'on va lier au materiel
347 325

  
348
                  $options = array ("itemtype" => $type,
349
                     "ID" => $ID,
350
                     "url" => $url,
351
                     "entities_id" => $line["entities_id"],
352
                     "rubrique" => $rubrique,
353
                     "suppliername" => $suppliername);
354
                  $values["documents_id"]=self::addDocument($options);
326
            if ($adddoc!=0 && $suppliername!="Dell") {
355 327

  
356
               }
328
               $options = array ("itemtype" => $type,
329
                  "ID" => $ID,
330
                  "url" => $url,
331
                  "entities_id" => $line["entities_id"],
332
                  "rubrique" => $rubrique,
333
                  "suppliername" => $suppliername);
334
               $values["documents_id"]=self::addDocument($options);
357 335

  
358
               //insert base locale
359
               $values["import_status"]=1;
360
               $values["items_id"]=$ID;
361
               $values["itemtype"]=$type;
362
               $values["date_import"]=$date;
363
               $log = new PluginManufacturersimportsLog();
364
               $log->add($values);
336
            }
365 337

  
366
               $_SESSION["glpi_plugin_manufacturersimports_total"]+=1;
338
            //insert base locale
339
            $values["import_status"]=1;
340
            $values["items_id"]=$ID;
341
            $values["itemtype"]=$type;
342
            $values["date_import"]=$date;
343
            $log = new PluginManufacturersimportsLog();
344
            $log->add($values);
367 345

  
368
            } else { // Failed check date
346
            $_SESSION["glpi_plugin_manufacturersimports_total"]+=1;
369 347

  
370
               self::isInError($type,$ID, $contents);
371
            }
372
         } else { // Failed checj contents
373
            self::isInError($type,$ID);
348
         } else { // Failed check date
349
            self::isInError($type,$ID, $contents);
374 350
         }
375 351

  
376 352
         echo "</tr>\n";
377
-