Esempio n. 1
0
function _import_oami(&$args, &$start, &$count)
{
    $result = '';
    $start = $count = 0;
    $ds = DIRECTORY_SEPARATOR;
    $root = sfConfig::get('sf_root_dir') . $ds . sfConfig::get('sf_web_dir_name') . $ds . "uploads" . $ds;
    $zipFile = $args[0];
    $source = $root . "zip" . $ds . $zipFile;
    $outDir = $root . "files" . $ds;
    $zip = new ZipArchive();
    $x = $zip->open($source);
    // open the zip file to extract
    if ($x == true) {
        // 20140502
        $nameParts = explode("_", $zipFile);
        $contestation = $nameParts[2];
        $contestationDate = date("Y-m-d", strtotime(substr($contestation, 0, 4) . "-" . substr($contestation, 4, 2) . "-" . substr($contestation, 6, 2) . " +3months"));
        //exit("\nContestationDate: ".$contestationDate."\n");
        $extract = $zip->extractTo($outDir);
        // place in the directory with same name
        $zip->close();
        //unlink($source);
        _echo_cms('SUCCESS: ZIP file has been unziped.');
        _echo_cms('--------------------------------------------------------------------------------');
        $files = array();
        $ind = 0;
        foreach (glob($outDir . '*.*') as $f) {
            $files[] = $f;
            //var_dump($f);
            $parts = pathinfo($f);
            if (substr($parts['basename'], 0, 10) == 'DIFF_CTMS_') {
                //					$c = new Criteria();
                //					$c->add(EmailTemplatePeer::ID, 7206, '>');
                //					EmailTemplatePeer::doDelete($c);
                //echo "*** done delete *** | ";
                $fileContent = file_get_contents($f);
                if ($fileContent !== false && $fileContent > '') {
                    _echo_cms_title("Importing XML file: " . $f);
                    $enc = mb_detect_encoding($fileContent, 'ISO-8859-1');
                    //var_dump($enc);
                    $mainData = json_decode(json_encode((array) simplexml_load_string($fileContent, null, LIBXML_NOCDATA)), 1);
                    //var_dump($mainData); //exit();
                    $trademarks = $mainData["TradeMarkTransactionBody"]["TransactionContentDetails"]["TransactionData"]["TradeMarkDetails"]["TradeMark"];
                    echo "cnt=" . count($trademarks) . "\n";
                    unset($mainData);
                    //var_dump($trademarks[0]); //die("\n-------------------\n");
                    foreach ($trademarks as $t) {
                        $dc = $t['DesignatedCountryDetails']['DesignatedCountry'];
                        $cc = array();
                        foreach ($dc as $dd) {
                            $cc[] = $dd['DesignatedCountryCode'];
                        }
                        //if(!in_array(array("EM","BG"),$cc)) continue;
                        if ($t['@attributes']['operationCode'] != 'Insert') {
                            continue;
                        }
                        // only INSERT
                        //var_dump($t); //_echo_cms('--------------------------------------------------------------------------------'); continue;
                        $c = new Criteria();
                        $c->add(TrademarkPeer::APPLICATION_NUMBER, $t['ApplicationNumber']);
                        $tm = TrademarkPeer::doSelectOne($c);
                        if (!$tm) {
                            $tm = new Trademark();
                        }
                        $tm->setFromSystem(2);
                        // OAMI
                        $tm->setApplicationNumber($t['ApplicationNumber']);
                        //if ($t['ApplicationNumber'] == '012438404') var_dump($t);
                        $tm->setApplicationDate($t['ApplicationDate']);
                        $tm->setRegisterNumber($t['BasicRegistrationApplicationDetails']['BasicRegistrationApplication']['BasicRegistrationDetails']['BasicRegistration']['BasicRegistrationNumber']);
                        $tm->setRegistrationDate($t['BasicRegistrationApplicationDetails']['BasicRegistrationApplication']['BasicRegistrationDetails']['BasicRegistration']['BasicRegistrationDate']);
                        $tm->setExpiresOn($t['ExpiryDate']);
                        //						$tm->setContestation($contestationDate);
                        $tm->setDesignatedContractingParty(implode(',', $cc));
                        if ($t['WordMarkSpecification']['MarkVerbalElementText']) {
                            $tm->setLabel($t['WordMarkSpecification']['MarkVerbalElementText']);
                        } else {
                            $tm->setLabel('no label trademark: ' . $t['ApplicationNumber']);
                        }
                        if (isset($t['MarkImageDetails']['MarkImage'])) {
                            if (isset($t['MarkImageDetails']['MarkImage']['MarkImageFilename'])) {
                                $img = $t['MarkImageDetails']['MarkImage']['MarkImageFilename'];
                            }
                            if (isset($t['MarkImageDetails']['MarkImage']['MarkImageCategory']['CategoryCodeDetails']['CategoryCode'])) {
                                if (is_array($t['MarkImageDetails']['MarkImage']['MarkImageCategory']['CategoryCodeDetails']['CategoryCode'])) {
                                    $tm->setViennaClasses(implode(',', $t['MarkImageDetails']['MarkImage']['MarkImageCategory']['CategoryCodeDetails']['CategoryCode']));
                                } else {
                                    $tm->setViennaClasses($t['MarkImageDetails']['MarkImage']['MarkImageCategory']['CategoryCodeDetails']['CategoryCode']);
                                }
                            }
                        }
                        if (isset($t['GoodsServicesDetails']['GoodsServices']['ClassDescriptionDetails']['ClassDescription'][0])) {
                            $codes = array();
                            foreach ($t['GoodsServicesDetails']['GoodsServices']['ClassDescriptionDetails']['ClassDescription'] as $ic) {
                                $codes[] = $ic['ClassNumber'];
                            }
                            $tm->setNiceClasses(implode(',', $codes));
                        } else {
                            $tm->setNiceClasses($t['GoodsServicesDetails']['GoodsServices']['ClassDescriptionDetails']['ClassDescription']['ClassNumber']);
                        }
                        if ($t['MarkFeature'] == 'Figurative') {
                            $tm->setKind('image');
                        } elseif ($t['MarkFeature'] == 'Word') {
                            $tm->setKind('text');
                        } elseif ($t['MarkFeature'] == 'Sound') {
                            $tm->setKind('sound');
                        } else {
                            $tm->setKind('mixed');
                        }
                        if (isset($t['ApplicantDetails']['ApplicantKey'][0])) {
                            $recs = array();
                            foreach ($t['ApplicantDetails']['ApplicantKey'] as $rr) {
                                $recs[] = $rr['Identifier'];
                            }
                            $tm->setRightsOwner(implode(',', $recs));
                            $tm->setRightsOwnerId(implode(',', $recs));
                        } else {
                            $tm->setRightsOwner($t['ApplicantDetails']['ApplicantKey']['Identifier']);
                            $tm->setRightsOwnerId($t['ApplicantDetails']['ApplicantKey']['Identifier']);
                        }
                        $tm->setRightsOwnerAddress('');
                        $tm->setRightsRepresentative($t['RepresentativeDetails']['RepresentativeKey']['Identifier']);
                        $tm->setRightsRepresentativeId($t['RepresentativeDetails']['RepresentativeKey']['Identifier']);
                        $tm->setRightsRepresentativeAddress('');
                        $tm->setOfficeOfOrigin($t['RegistrationOfficeCode']);
                        $tm->setStatus($t['MarkCurrentStatusCode']);
                        $pDate = '-';
                        $pub = '-';
                        $contestation = '-';
                        if (isset($t['PublicationDetails']['Publication'])) {
                            //							_echo_cms("* checking #$ind: ".$tm->getLabel());
                            // if we have multiple publications
                            if (isset($t['PublicationDetails']['Publication'][0])) {
                                //_echo_cms("A) checking #$ind: ".$tm->getLabel());
                                /*								$recs = array();
                                								foreach ($t['PublicationDetails']['Publication'] as $pp)
                                								{
                                								$recs[] = $pp['PublicationDate'].' | '.$pp['PublicationIdentifier'].' | '.$pp['PublicationSection'];
                                								}
                                								$tm->setPublications(implode("\n", $recs));*/
                                $recs = '';
                                $found = false;
                                foreach ($t['PublicationDetails']['Publication'] as $pp) {
                                    $recs = $pp['PublicationDate'] . ' | ' . $pp['PublicationIdentifier'] . ' | ' . $pp['PublicationSection'];
                                    $pDate = $pp['PublicationDate'];
                                    $pub = $pp['PublicationSection'];
                                    $today = date('Y-m-d');
                                    if ($pp['PublicationSection'] == 'M.1') {
                                        $contestation = date('Y-m-d', strtotime("+10 months", strtotime($pp['PublicationDate'])));
                                        if ($today > $contestation) {
                                            //echo "SKIP M1: $today > $contestation | ";
                                            continue;
                                        }
                                        //echo "FOUND M1: $today  < $contestation \n";
                                        $contestation = date('Y-m-d', strtotime("+9 months", strtotime($pp['PublicationDate'])));
                                        $tm->setContestation($contestation);
                                        $found = true;
                                    } else {
                                        if ($pp['PublicationSection'] == 'A.1') {
                                            $contestation = date('Y-m-d', strtotime("+4 months", strtotime($pp['PublicationDate'])));
                                            if ($today > $contestation) {
                                                //echo "SKIP A1: $today > $contestation | ";
                                                continue;
                                            }
                                            //echo "FOUND A1: $today  < $contestation \n";
                                            $contestation = date('Y-m-d', strtotime("+3 months", strtotime($pp['PublicationDate'])));
                                            $tm->setContestation($contestation);
                                            $found = true;
                                        }
                                    }
                                }
                                if (!$found) {
                                    //echo " > Not Found\n";
                                    continue;
                                }
                                $tm->setPublications($recs);
                            } else {
                                //_echo_cms("B) checking #$ind: ".$tm->getLabel());
                                $pDate = $t['PublicationDetails']['Publication']['PublicationDate'];
                                $pub = $t['PublicationDetails']['Publication']['PublicationSection'];
                                $today = date('Y-m-d');
                                if ($pub == 'M.1') {
                                    $contestation = date('Y-m-d', strtotime("+10 months", strtotime($pDate)));
                                    if ($today > $contestation) {
                                        //echo "SKIP M1: $today > $contestation \n";
                                        continue;
                                    }
                                    //echo "FOUND M1: $today  < $contestation \n";
                                    $contestation = date('Y-m-d', strtotime("+9 months", strtotime($pDate)));
                                    $tm->setContestation($contestation);
                                } else {
                                    if ($pub == 'A.1') {
                                        $contestation = date('Y-m-d', strtotime("+4 months", strtotime($pDate)));
                                        if ($today > $contestation) {
                                            //echo "SKIP A1: $today > $contestation \n";
                                            continue;
                                        }
                                        //echo "FOUND A1: $today  < $contestation \n";
                                        $contestation = date('Y-m-d', strtotime("+3 months", strtotime($pDate)));
                                        $tm->setContestation($contestation);
                                    } else {
                                        //echo " > Not Found A1 or M1\n";
                                        continue;
                                        // skip OTHER Publications except A.1 and M.1
                                    }
                                }
                                $tm->setPublications($t['PublicationDetails']['Publication']['PublicationDate'] . ' | ' . $t['PublicationDetails']['Publication']['PublicationIdentifier'] . ' | ' . $t['PublicationDetails']['Publication']['PublicationSection']);
                            }
                        } else {
                            //echo "SKIP: #$ind: ".$tm->getLabel()." : NO PUBLICATION\n";
                            continue;
                        }
                        $tm->save();
                        if ($start == 0) {
                            $start = $tm->getId();
                        }
                        $ind++;
                        $count++;
                        _echo_cms("{$ind}: " . $tm->getLabel() . " | pub={$pub}, contestation={$contestation}");
                    }
                    unset($trademarks);
                }
                echo "*** XML import done! ***\n";
                unset($fileContent);
                $result = 'imported';
            }
        }
        //var_dump($files);
        foreach ($files as $f) {
            @unlink($f);
        }
    } else {
        _echo_cms_error('ERROR: Error unzipping uploaded file.');
        $result = 'error';
    }
    return $result;
}
Esempio n. 2
0
 public function executeAddNewTrademark()
 {
     $this->setLayout(false);
     $this->trademarkTypes = UtilsHelper::loadTrademarkTypes();
     if ($trademark = Document::getDocumentInstance($this->getRequestParameter('trademark_id'))) {
         if (get_class($trademark) != 'Trademark') {
             $trademark = null;
         }
     }
     if (!$trademark) {
         $trademark = new Trademark();
     }
     $ownersArr = array();
     $root = Rootfolder::getRootfolderByModule('clients');
     $owners = Document::getChildrenOf($root->getId(), 'Client');
     foreach ($owners as $ow) {
         $ownersArr[$ow->getId()] = $ow->getLabel();
     }
     $this->ownersArr = $ownersArr;
     $success = false;
     if ($this->getRequestParameter('submit') > '') {
         // check input data
         $request = $this->getRequest();
         $params = $request->getParameterHolder()->getAll();
         //var_dump($params);
         $errors = false;
         $fields = array("label" => 'Наименование', "application_number" => 'Заявка номер', "kind" => 'Тип', "application_date" => 'Дата на заявяване', "expires_on" => 'Срок', "contestation" => 'Краен срок за опозиция', "nice_classes" => 'Класове по Ницска класификация', "rights_owner" => 'Притежател', "office_of_origin" => 'Държава на регистрация', "designated_contracting_party" => 'Държави в които е в сила');
         foreach ($fields as $fl => $label) {
             $val = trim($params[$fl]);
             if ($val == '') {
                 if ($fl == 'rights_owner') {
                     if ($params['owner'] == '') {
                         $errors = true;
                         $request->setError('err' . $fl, '- ' . $label);
                     }
                 } else {
                     $errors = true;
                     $request->setError('err' . $fl, '- ' . $label);
                 }
             }
         }
         $image = null;
         if ($errors) {
             UtilsHelper::setFlashMsg('Моля, въведете необходимите данни:<br>', UtilsHelper::MSG_ERROR);
         } else {
             if ($request->getFileName('image')) {
                 try {
                     $image = Media::upload('image', 'upload', array('image/gif', 'image/jpeg', 'image/jpg', 'image/png'));
                     //var_dump($image);
                     list($w, $h) = getimagesize($image->getServerAbsoluteUrl());
                     if ($w > $h) {
                         $image->resizeImage("thumbs", null, 105);
                     } else {
                         $image->resizeImage("thumbs", 95);
                     }
                 } catch (Exception $e) {
                     $errors = true;
                     $request->setError('errImage', '- ' . UtilsHelper::Localize('media.' . $e->getMessage()));
                 }
             }
             if ($errors) {
                 // remove uploaded image
                 if ($image) {
                     $image->delete();
                 }
                 UtilsHelper::setFlashMsg('Моля, коригирайте:<br>', UtilsHelper::MSG_ERROR);
             }
         }
         // if everithing is OK
         if (!$errors) {
             //$trademark = new Brand();
             $trademark->setLabel($params['label']);
             $trademark->setFromSystem(1);
             if ($params['owner'] > '') {
                 //$trademark->setClientId($params['owner']);
                 $client = Document::getDocumentInstance($params['owner']);
                 $trademark->setRightsOwner($client->getLabel());
             } else {
                 $val = trim($params['rights_owner']);
                 $client = new Client();
                 $client->setLabel($val);
                 $client->save();
                 //$trademark->setClientId($client->getId());
                 $this->client = $client;
                 $trademark->setRightsOwner($val);
             }
             $trademark->setApplicationNumber($params['application_number']);
             $trademark->setRegisterNumber($params['register_number']);
             if ($params['registration_date']) {
                 $trademark->setRegistrationDate($params['registration_date']);
             }
             $trademark->setKind($params['kind']);
             $trademark->setApplicationDate($params['application_date']);
             $trademark->setStatus($params['status']);
             $trademark->setExpiresOn($params['expires_on']);
             $trademark->setContestation($params['contestation']);
             $trademark->setPublications($params['publications']);
             $trademark->setViennaClasses(str_replace(' ', '', $params['vienna_classes']));
             $trademark->setColors($params['colors']);
             $trademark->setNiceClasses(str_replace(' ', '', $params['nice_classes']));
             $trademark->setRightsOwnerAddress($params['rights_owner_address']);
             $trademark->setRightsRepresentative($params['rights_representative']);
             $trademark->setRightsRepresentativeAddress($params['rights_representative_address']);
             $trademark->setOfficeOfOrigin($params['office_of_origin']);
             $trademark->setDesignatedContractingParty($params['designated_contracting_party']);
             if ($image) {
                 $trademark->setImage($image->getId());
             }
             $trademark->save();
             $success = true;
         }
     }
     $this->trademark = $trademark;
     $this->success = $success;
 }