[ Index ] |
PHP Cross Reference of vtigercrm-6.1.0 |
[Summary view] [Print] [Text view]
1 <?php 2 /*+********************************************************************************** 3 * The contents of this file are subject to the vtiger CRM Public License Version 1.0 4 * ("License"); You may not use this file except in compliance with the License 5 * The Original Code is: vtiger CRM Open Source 6 * The Initial Developer of the Original Code is vtiger. 7 * Portions created by vtiger are Copyright (C) vtiger. 8 * All Rights Reserved. 9 ************************************************************************************/ 10 include_once ('vtlib/Vtiger/PackageExport.php'); 11 include_once ('vtlib/Vtiger/Unzip.php'); 12 include_once ('vtlib/Vtiger/Module.php'); 13 include_once ('vtlib/Vtiger/Event.php'); 14 include_once ('vtlib/Vtiger/Cron.php'); 15 16 /** 17 * Provides API to import module into vtiger CRM 18 * @package vtlib 19 */ 20 class Vtiger_PackageImport extends Vtiger_PackageExport { 21 22 /** 23 * Module Meta XML File (Parsed) 24 * @access private 25 */ 26 var $_modulexml; 27 /** 28 * Module Fields mapped by [modulename][fieldname] which 29 * will be used to create customviews. 30 * @access private 31 */ 32 var $_modulefields_cache = Array(); 33 34 /** 35 * License of the package. 36 * @access private 37 */ 38 var $_licensetext = false; 39 40 /** 41 * Constructor 42 */ 43 function Vtiger_PackageImport() { 44 parent::__construct(); 45 } 46 47 /** 48 * Parse the manifest file 49 * @access private 50 */ 51 function __parseManifestFile($unzip) { 52 $manifestfile = $this->__getManifestFilePath(); 53 $unzip->unzip('manifest.xml', $manifestfile); 54 $this->_modulexml = simplexml_load_file($manifestfile); 55 unlink($manifestfile); 56 } 57 58 /** 59 * Get type of package (as specified in manifest) 60 */ 61 function type() { 62 if(!empty($this->_modulexml) && !empty($this->_modulexml->type)) { 63 return $this->_modulexml->type; 64 } 65 return false; 66 } 67 68 /** 69 * XPath evaluation on the root module node. 70 * @param String Path expression 71 */ 72 function xpath($path) { 73 return $this->_modulexml->xpath($path); 74 } 75 76 /** 77 * Get the value of matching path (instead of complete xpath result) 78 * @param String Path expression for which value is required 79 */ 80 function xpath_value($path) { 81 $xpathres = $this->xpath($path); 82 foreach($xpathres as $pathkey=>$pathvalue) { 83 if($pathkey == $path) return $pathvalue; 84 } 85 return false; 86 } 87 88 /** 89 * Are we trying to import layout package? 90 */ 91 function isLanguageType($zipfile =null) { 92 if(!empty($zipfile)) { 93 if(!$this->checkZip($zipfile)) { 94 return false; 95 } 96 } 97 $packagetype = $this->type(); 98 99 if($packagetype) { 100 $lcasetype = strtolower($packagetype); 101 if($lcasetype == 'language') return true; 102 } 103 if($packagetype) { 104 $lcasetype = strtolower($packagetype); 105 if($lcasetype == 'layout') return true; 106 } 107 return false; 108 } 109 110 /** 111 * Are we trying to import extension package? 112 */ 113 function isExtensionType($zipfile =null) { 114 if(!empty($zipfile)) { 115 if(!$this->checkZip($zipfile)) { 116 return false; 117 } 118 } 119 $packagetype = $this->type(); 120 121 if($packagetype) { 122 $lcasetype = strtolower($packagetype); 123 if($lcasetype == 'extension') return true; 124 } 125 return false; 126 } 127 128 /** 129 * Are we trying to import language package? 130 */ 131 function isLayoutType($zipfile =null) { 132 if(!empty($zipfile)) { 133 if(!$this->checkZip($zipfile)) { 134 return false; 135 } 136 } 137 $packagetype = $this->type(); 138 139 if($packagetype) { 140 $lcasetype = strtolower($packagetype); 141 if($lcasetype == 'layout') return true; 142 } 143 return false; 144 } 145 146 /** 147 * checks whether a package is module bundle or not. 148 * @param String $zipfile - path to the zip file. 149 * @return Boolean - true if given zipfile is a module bundle and false otherwise. 150 */ 151 function isModuleBundle($zipfile = null) { 152 // If data is not yet available 153 if(!empty($zipfile)) { 154 if(!$this->checkZip($zipfile)) { 155 return false; 156 } 157 } 158 159 return (boolean)$this->_modulexml->modulebundle; 160 } 161 162 /** 163 * @return Array module list available in the module bundle. 164 */ 165 function getAvailableModuleInfoFromModuleBundle() { 166 $list = (Array)$this->_modulexml->modulelist; 167 return (Array)$list['dependent_module']; 168 } 169 170 /** 171 * Get the license of this package 172 * NOTE: checkzip should have been called earlier. 173 */ 174 function getLicense() { 175 return $this->_licensetext; 176 } 177 178 /** 179 * Check if zipfile is a valid package 180 * @access private 181 */ 182 function checkZip($zipfile) { 183 $unzip = new Vtiger_Unzip($zipfile); 184 $filelist = $unzip->getList(); 185 186 $manifestxml_found = false; 187 $languagefile_found = false; 188 $layoutfile_found = false; 189 $vtigerversion_found = false; 190 191 $modulename = null; 192 $language_modulename = null; 193 194 foreach($filelist as $filename=>$fileinfo) { 195 $matches = Array(); 196 preg_match('/manifest.xml/', $filename, $matches); 197 if(count($matches)) { 198 $manifestxml_found = true; 199 $this->__parseManifestFile($unzip); 200 $modulename = $this->_modulexml->name; 201 $isModuleBundle = (string)$this->_modulexml->modulebundle; 202 203 if($isModuleBundle === 'true' && (!empty($this->_modulexml)) && 204 (!empty($this->_modulexml->dependencies)) && 205 (!empty($this->_modulexml->dependencies->vtiger_version))) { 206 $languagefile_found = true; 207 break; 208 } 209 210 // Do we need to check the zip further? 211 if($this->isLanguageType()) { 212 $languagefile_found = true; // No need to search for module language file. 213 break; 214 }else if($this->isLayoutType()){ 215 $layoutfile_found = true; // No need to search for module language file. 216 break; 217 }else if($this->isExtensionType()){ 218 $extensionfile_found = true; // No need to search for module language file. 219 break; 220 }else { 221 continue; 222 } 223 } 224 // Language file present in en_us folder 225 $pattern = '/languages\/en_us\/([^\/]+).php/'; 226 preg_match($pattern, $filename, $matches); 227 if(count($matches)) { $language_modulename = $matches[1]; } 228 229 // or Language file may be present in en_us/Settings folder 230 $settingsPattern = '/languages\/en_us\/Settings\/([^\/]+).php/'; 231 preg_match($settingsPattern, $filename, $matches); 232 if(count($matches)) { $language_modulename = $matches[1]; } 233 } 234 235 // Verify module language file. 236 if(!empty($language_modulename) && $language_modulename == $modulename) { 237 $languagefile_found = true; 238 } 239 240 if(!empty($this->_modulexml) && 241 !empty($this->_modulexml->dependencies) && 242 !empty($this->_modulexml->dependencies->vtiger_version)) { 243 $vtigerVersion = (string)$this->_modulexml->dependencies->vtiger_version; 244 if(version_compare($vtigerVersion, '6.0.0rc', '>=') === true) { 245 $vtigerversion_found = true; 246 } 247 } 248 249 $validzip = false; 250 if($manifestxml_found && $languagefile_found && $vtigerversion_found) 251 $validzip = true; 252 253 if($manifestxml_found && $layoutfile_found && $vtigerversion_found) 254 $validzip = true; 255 256 if($manifestxml_found && $extensionfile_found && $vtigerversion_found) 257 $validzip = true; 258 259 if($validzip) { 260 if(!empty($this->_modulexml->license)) { 261 if(!empty($this->_modulexml->license->inline)) { 262 $this->_licensetext = $this->_modulexml->license->inline; 263 } else if(!empty($this->_modulexml->license->file)) { 264 $licensefile = $this->_modulexml->license->file; 265 $licensefile = "$licensefile"; 266 if(!empty($filelist[$licensefile])) { 267 $this->_licensetext = $unzip->unzip($licensefile); 268 } else { 269 $this->_licensetext = "Missing $licensefile!"; 270 } 271 } 272 } 273 } 274 275 if($unzip) $unzip->close(); 276 277 return $validzip; 278 } 279 280 /** 281 * Get module name packaged in the zip file 282 * @access private 283 */ 284 function getModuleNameFromZip($zipfile) { 285 if(!$this->checkZip($zipfile)) return null; 286 287 return (string)$this->_modulexml->name; 288 } 289 290 /** 291 * returns the name of the module. 292 * @return String - name of the module as given in manifest file. 293 */ 294 function getModuleName() { 295 return (string)$this->_modulexml->name; 296 } 297 298 /** 299 * Cache the field instance for re-use 300 * @access private 301 */ 302 function __AddModuleFieldToCache($moduleInstance, $fieldname, $fieldInstance) { 303 $this->_modulefields_cache["$moduleInstance->name"]["$fieldname"] = $fieldInstance; 304 } 305 306 /** 307 * Get field instance from cache 308 * @access private 309 */ 310 function __GetModuleFieldFromCache($moduleInstance, $fieldname) { 311 return $this->_modulefields_cache["$moduleInstance->name"]["$fieldname"]; 312 } 313 314 /** 315 * Initialize Import 316 * @access private 317 */ 318 function initImport($zipfile, $overwrite=true) { 319 $module = $this->getModuleNameFromZip($zipfile); 320 if($module != null) { 321 322 $unzip = new Vtiger_Unzip($zipfile, $overwrite); 323 324 // Unzip selectively 325 $unzip->unzipAllEx( ".", 326 Array( 327 // Include only file/folders that need to be extracted 328 'include' => Array('templates', "modules/$module", 'cron', 'languages', 329 'settings/actions', 'settings/views', 'settings/models', 'settings/templates', 'settings/connectors', 'settings/libraries', 330 "$module.png"), 331 // NOTE: If excludes is not given then by those not mentioned in include are ignored. 332 ), 333 // What files needs to be renamed? 334 Array( 335 // Templates folder 336 'templates' => "layouts/vlayout/modules/$module", 337 // Cron folder 338 'cron' => "cron/modules/$module", 339 // Settings folder 340 'settings/actions' => "modules/Settings/$module/actions", 341 'settings/views' => "modules/Settings/$module/views", 342 'settings/models' => "modules/Settings/$module/models", 343 'settings/connectors' => "modules/Settings/$module/connectors", 344 'settings/libraries' => "modules/Settings/$module/libraries", 345 // Settings templates folder 346 'settings/templates' => "layouts/vlayout/modules/Settings/$module", 347 //module images 348 'images' => "layouts/vlayout/skins/images/$module", 349 'settings' => "modules/Settings", 350 ) 351 ); 352 353 if($unzip->checkFileExistsInRootFolder("$module.png")) { 354 $unzip->unzip("$module.png", "layouts/vlayout/skins/images/$module.png"); 355 } 356 357 if($unzip) $unzip->close(); 358 } 359 return $module; 360 } 361 362 function getTemporaryFilePath($filepath=false) { 363 return 'cache/'. $filepath; 364 } 365 /** 366 * Get dependent version 367 * @access private 368 */ 369 function getDependentVtigerVersion() { 370 return $this->_modulexml->dependencies->vtiger_version; 371 } 372 373 /** 374 * Get dependent Maximum version 375 * @access private 376 */ 377 function getDependentMaxVtigerVersion() { 378 return $this->_modulexml->dependencies->vtiger_max_version; 379 } 380 381 /** 382 * Get package version 383 * @access private 384 */ 385 function getVersion() { 386 return $this->_modulexml->version; 387 } 388 389 /** 390 * Get package author name 391 * @access private 392 */ 393 function getAuthorName() { 394 return $this->_modulexml->authorname; 395 } 396 397 /** 398 * Get package author phone number 399 * @access private 400 */ 401 function getAuthorPhone() { 402 return $this->_modulexml->authorphone; 403 } 404 405 /** 406 * Get package author phone email 407 * @access private 408 */ 409 function getAuthorEmail() { 410 return $this->_modulexml->authoremail; 411 } 412 413 /** 414 * Get package author phone email 415 * @access private 416 */ 417 function getDescription() { 418 return $this->_modulexml->description; 419 } 420 421 422 /** 423 * Import Module from zip file 424 * @param String Zip file name 425 * @param Boolean True for overwriting existing module 426 * 427 * @todo overwrite feature is not functionally currently. 428 */ 429 function import($zipfile, $overwrite=false) { 430 $module = $this->getModuleNameFromZip($zipfile); 431 if($module != null) { 432 // If data is not yet available 433 if(empty($this->_modulexml)) { 434 $this->__parseManifestFile($unzip); 435 } 436 437 $buildModuleArray = array(); 438 $installSequenceArray = array(); 439 $moduleBundle = (boolean)$this->_modulexml->modulebundle; 440 if($moduleBundle == true) { 441 $moduleList = (Array)$this->_modulexml->modulelist; 442 foreach($moduleList as $moduleInfos) { 443 foreach($moduleInfos as $moduleInfo) { 444 $moduleInfo = (Array)$moduleInfo; 445 $buildModuleArray[] = $moduleInfo; 446 $installSequenceArray[] = $moduleInfo['install_sequence']; 447 } 448 } 449 sort($installSequenceArray); 450 $unzip = new Vtiger_Unzip($zipfile); 451 $unzip->unzipAllEx($this->getTemporaryFilePath()); 452 foreach ($installSequenceArray as $sequence) { 453 foreach ($buildModuleArray as $moduleInfo) { 454 if($moduleInfo['install_sequence'] == $sequence) { 455 $this->import($this->getTemporaryFilePath($moduleInfo['filepath']), $overwrite); 456 } 457 } 458 } 459 } else { 460 $module = $this->initImport($zipfile, $overwrite); 461 // Call module import function 462 $this->import_Module(); 463 } 464 } 465 } 466 467 468 /** 469 * Import Module 470 * @access private 471 */ 472 function import_Module() { 473 $tabname = $this->_modulexml->name; 474 $tablabel= $this->_modulexml->label; 475 $parenttab=(string)$this->_modulexml->parent; 476 $tabversion=$this->_modulexml->version; 477 478 $isextension= false; 479 if(!empty($this->_modulexml->type)) { 480 $type = strtolower($this->_modulexml->type); 481 if($type == 'extension' || $type == 'language') 482 $isextension = true; 483 } 484 485 $vtigerMinVersion = $this->_modulexml->dependencies->vtiger_version; 486 $vtigerMaxVersion = $this->_modulexml->dependencies->vtiger_max_version; 487 488 $moduleInstance = new Vtiger_Module(); 489 $moduleInstance->name = $tabname; 490 $moduleInstance->label= $tablabel; 491 $moduleInstance->parent=$parenttab; 492 $moduleInstance->isentitytype = ($isextension != true); 493 $moduleInstance->version = (!$tabversion)? 0 : $tabversion; 494 $moduleInstance->minversion = (!$vtigerMinVersion)? false : $vtigerMinVersion; 495 $moduleInstance->maxversion = (!$vtigerMaxVersion)? false : $vtigerMaxVersion; 496 $moduleInstance->save(); 497 498 if(!empty($parenttab)) { 499 $menuInstance = Vtiger_Menu::getInstance($parenttab); 500 $menuInstance->addModule($moduleInstance); 501 } 502 503 $this->import_Tables($this->_modulexml); 504 $this->import_Blocks($this->_modulexml, $moduleInstance); 505 $this->import_CustomViews($this->_modulexml, $moduleInstance); 506 $this->import_SharingAccess($this->_modulexml, $moduleInstance); 507 $this->import_Events($this->_modulexml, $moduleInstance); 508 $this->import_Actions($this->_modulexml, $moduleInstance); 509 $this->import_RelatedLists($this->_modulexml, $moduleInstance); 510 $this->import_CustomLinks($this->_modulexml, $moduleInstance); 511 $this->import_CronTasks($this->_modulexml); 512 513 Vtiger_Module::fireEvent($moduleInstance->name, 514 Vtiger_Module::EVENT_MODULE_POSTINSTALL); 515 516 $moduleInstance->initWebservice(); 517 } 518 519 /** 520 * Import Tables of the module 521 * @access private 522 */ 523 function import_Tables($modulenode) { 524 if(empty($modulenode->tables) || empty($modulenode->tables->table)) return; 525 526 /** 527 * Record the changes in schema file 528 */ 529 530 if(file_exists("modules/$modulenode->name")){ 531 $fileToOpen = "modules/$modulenode->name/schema.xml"; 532 } else if(file_exists("modules/Settings/$modulenode->name")){ 533 $fileToOpen = "modules/Settings/$modulenode->name/schema.xml"; 534 } 535 $schemafile = fopen($fileToOpen, 'w'); 536 if($schemafile) { 537 fwrite($schemafile, "<?xml version='1.0'?>\n"); 538 fwrite($schemafile, "<schema>\n"); 539 fwrite($schemafile, "\t<tables>\n"); 540 } 541 542 // Import the table via queries 543 foreach($modulenode->tables->table as $tablenode) { 544 $tablename = $tablenode->name; 545 $tablesql = "$tablenode->sql"; // Convert to string format 546 547 // Save the information in the schema file. 548 fwrite($schemafile, "\t\t<table>\n"); 549 fwrite($schemafile, "\t\t\t<name>$tablename</name>\n"); 550 fwrite($schemafile, "\t\t\t<sql><![CDATA[$tablesql]]></sql>\n"); 551 fwrite($schemafile, "\t\t</table>\n"); 552 553 // Avoid executing SQL that will DELETE or DROP table data 554 if(Vtiger_Utils::IsCreateSql($tablesql)) { 555 if(!Vtiger_Utils::checkTable($tablename)) { 556 self::log("SQL: $tablesql ... ", false); 557 Vtiger_Utils::ExecuteQuery($tablesql); 558 self::log("DONE"); 559 } 560 } else { 561 if(Vtiger_Utils::IsDestructiveSql($tablesql)) { 562 self::log("SQL: $tablesql ... SKIPPED"); 563 } else { 564 self::log("SQL: $tablesql ... ", false); 565 Vtiger_Utils::ExecuteQuery($tablesql); 566 self::log("DONE"); 567 } 568 } 569 } 570 if($schemafile) { 571 fwrite($schemafile, "\t</tables>\n"); 572 fwrite($schemafile, "</schema>\n"); 573 fclose($schemafile); 574 } 575 } 576 577 /** 578 * Import Blocks of the module 579 * @access private 580 */ 581 function import_Blocks($modulenode, $moduleInstance) { 582 if(empty($modulenode->blocks) || empty($modulenode->blocks->block)) return; 583 foreach($modulenode->blocks->block as $blocknode) { 584 $blockInstance = $this->import_Block($modulenode, $moduleInstance, $blocknode); 585 $this->import_Fields($blocknode, $blockInstance, $moduleInstance); 586 } 587 } 588 589 /** 590 * Import Block of the module 591 * @access private 592 */ 593 function import_Block($modulenode, $moduleInstance, $blocknode) { 594 $blocklabel = $blocknode->label; 595 596 $blockInstance = new Vtiger_Block(); 597 $blockInstance->label = $blocklabel; 598 $moduleInstance->addBlock($blockInstance); 599 return $blockInstance; 600 } 601 602 /** 603 * Import Fields of the module 604 * @access private 605 */ 606 function import_Fields($blocknode, $blockInstance, $moduleInstance) { 607 if(empty($blocknode->fields) || empty($blocknode->fields->field)) return; 608 609 foreach($blocknode->fields->field as $fieldnode) { 610 $fieldInstance = $this->import_Field($blocknode, $blockInstance, $moduleInstance, $fieldnode); 611 } 612 } 613 614 /** 615 * Import Field of the module 616 * @access private 617 */ 618 function import_Field($blocknode, $blockInstance, $moduleInstance, $fieldnode) { 619 $fieldInstance = new Vtiger_Field(); 620 $fieldInstance->name = $fieldnode->fieldname; 621 $fieldInstance->label = $fieldnode->fieldlabel; 622 $fieldInstance->table = $fieldnode->tablename; 623 $fieldInstance->column = $fieldnode->columnname; 624 $fieldInstance->uitype = $fieldnode->uitype; 625 $fieldInstance->generatedtype= $fieldnode->generatedtype; 626 $fieldInstance->readonly = $fieldnode->readonly; 627 $fieldInstance->presence = $fieldnode->presence; 628 $fieldInstance->defaultvalue = $fieldnode->defaultvalue; 629 $fieldInstance->maximumlength= $fieldnode->maximumlength; 630 $fieldInstance->sequence = $fieldnode->sequence; 631 $fieldInstance->quickcreate = $fieldnode->quickcreate; 632 $fieldInstance->quicksequence= $fieldnode->quickcreatesequence; 633 $fieldInstance->typeofdata = $fieldnode->typeofdata; 634 $fieldInstance->displaytype = $fieldnode->displaytype; 635 $fieldInstance->info_type = $fieldnode->info_type; 636 637 if(!empty($fieldnode->helpinfo)) 638 $fieldInstance->helpinfo = $fieldnode->helpinfo; 639 640 if(isset($fieldnode->masseditable)) 641 $fieldInstance->masseditable = $fieldnode->masseditable; 642 643 if(isset($fieldnode->columntype) && !empty($fieldnode->columntype)) 644 $fieldInstance->columntype = $fieldnode->columntype; 645 646 $blockInstance->addField($fieldInstance); 647 648 // Set the field as entity identifier if marked. 649 if(!empty($fieldnode->entityidentifier)) { 650 $moduleInstance->entityidfield = $fieldnode->entityidentifier->entityidfield; 651 $moduleInstance->entityidcolumn= $fieldnode->entityidentifier->entityidcolumn; 652 $moduleInstance->setEntityIdentifier($fieldInstance); 653 } 654 655 // Check picklist values associated with field if any. 656 if(!empty($fieldnode->picklistvalues) && !empty($fieldnode->picklistvalues->picklistvalue)) { 657 $picklistvalues = Array(); 658 foreach($fieldnode->picklistvalues->picklistvalue as $picklistvaluenode) { 659 $picklistvalues[] = $picklistvaluenode; 660 } 661 $fieldInstance->setPicklistValues( $picklistvalues ); 662 } 663 664 // Check related modules associated with this field 665 if(!empty($fieldnode->relatedmodules) && !empty($fieldnode->relatedmodules->relatedmodule)) { 666 $relatedmodules = Array(); 667 foreach($fieldnode->relatedmodules->relatedmodule as $relatedmodulenode) { 668 $relatedmodules[] = $relatedmodulenode; 669 } 670 $fieldInstance->setRelatedModules($relatedmodules); 671 } 672 673 // Set summary field if marked in xml 674 if(!empty($fieldnode->summaryfield)) { 675 $fieldInstance->setSummaryField($fieldnode->summaryfield); 676 } 677 678 $this->__AddModuleFieldToCache($moduleInstance, $fieldnode->fieldname, $fieldInstance); 679 return $fieldInstance; 680 } 681 682 /** 683 * Import Custom views of the module 684 * @access private 685 */ 686 function import_CustomViews($modulenode, $moduleInstance) { 687 if(empty($modulenode->customviews) || empty($modulenode->customviews->customview)) return; 688 foreach($modulenode->customviews->customview as $customviewnode) { 689 $filterInstance = $this->import_CustomView($modulenode, $moduleInstance, $customviewnode); 690 691 } 692 } 693 694 /** 695 * Import Custom View of the module 696 * @access private 697 */ 698 function import_CustomView($modulenode, $moduleInstance, $customviewnode) { 699 $viewname = $customviewnode->viewname; 700 $setdefault=$customviewnode->setdefault; 701 $setmetrics=$customviewnode->setmetrics; 702 703 $filterInstance = new Vtiger_Filter(); 704 $filterInstance->name = $viewname; 705 $filterInstance->isdefault = $setdefault; 706 $filterInstance->inmetrics = $setmetrics; 707 708 $moduleInstance->addFilter($filterInstance); 709 710 foreach($customviewnode->fields->field as $fieldnode) { 711 $fieldInstance = $this->__GetModuleFieldFromCache($moduleInstance, $fieldnode->fieldname); 712 $filterInstance->addField($fieldInstance, $fieldnode->columnindex); 713 714 if(!empty($fieldnode->rules->rule)) { 715 foreach($fieldnode->rules->rule as $rulenode) { 716 $filterInstance->addRule($fieldInstance, $rulenode->comparator, $rulenode->value, $rulenode->columnindex); 717 } 718 } 719 } 720 } 721 722 /** 723 * Import Sharing Access of the module 724 * @access private 725 */ 726 function import_SharingAccess($modulenode, $moduleInstance) { 727 if(empty($modulenode->sharingaccess)) return; 728 729 if(!empty($modulenode->sharingaccess->default)) { 730 foreach($modulenode->sharingaccess->default as $defaultnode) { 731 $moduleInstance->setDefaultSharing($defaultnode); 732 } 733 } 734 } 735 736 /** 737 * Import Events of the module 738 * @access private 739 */ 740 function import_Events($modulenode, $moduleInstance) { 741 if(empty($modulenode->events) || empty($modulenode->events->event)) return; 742 743 if(Vtiger_Event::hasSupport()) { 744 foreach($modulenode->events->event as $eventnode) { 745 $this->import_Event($modulenode, $moduleInstance, $eventnode); 746 } 747 } 748 } 749 750 /** 751 * Import Event of the module 752 * @access private 753 */ 754 function import_Event($modulenode, $moduleInstance, $eventnode) { 755 $event_condition = ''; 756 $event_dependent = '[]'; 757 if(!empty($eventnode->condition)) $event_condition = "$eventnode->condition"; 758 if(!empty($eventnode->dependent)) $event_dependent = "$eventnode->dependent"; 759 Vtiger_Event::register($moduleInstance, 760 (string)$eventnode->eventname, (string)$eventnode->classname, 761 (string)$eventnode->filename, (string)$event_condition, (string)$event_dependent 762 ); 763 } 764 765 /** 766 * Import actions of the module 767 * @access private 768 */ 769 function import_Actions($modulenode, $moduleInstance) { 770 if(empty($modulenode->actions) || empty($modulenode->actions->action)) return; 771 foreach($modulenode->actions->action as $actionnode) { 772 $this->import_Action($modulenode, $moduleInstance, $actionnode); 773 } 774 } 775 776 /** 777 * Import action of the module 778 * @access private 779 */ 780 function import_Action($modulenode, $moduleInstance, $actionnode) { 781 $actionstatus = $actionnode->status; 782 if($actionstatus == 'enabled') 783 $moduleInstance->enableTools($actionnode->name); 784 else 785 $moduleInstance->disableTools($actionnode->name); 786 } 787 788 /** 789 * Import related lists of the module 790 * @access private 791 */ 792 function import_RelatedLists($modulenode, $moduleInstance) { 793 if(empty($modulenode->relatedlists) || empty($modulenode->relatedlists->relatedlist)) return; 794 foreach($modulenode->relatedlists->relatedlist as $relatedlistnode) { 795 $relModuleInstance = $this->import_Relatedlist($modulenode, $moduleInstance, $relatedlistnode); 796 } 797 } 798 799 /** 800 * Import related list of the module. 801 * @access private 802 */ 803 function import_Relatedlist($modulenode, $moduleInstance, $relatedlistnode) { 804 $relModuleInstance = Vtiger_Module::getInstance($relatedlistnode->relatedmodule); 805 $label = $relatedlistnode->label; 806 $actions = false; 807 if(!empty($relatedlistnode->actions) && !empty($relatedlistnode->actions->action)) { 808 $actions = Array(); 809 foreach($relatedlistnode->actions->action as $actionnode) { 810 $actions[] = "$actionnode"; 811 } 812 } 813 if($relModuleInstance) { 814 $moduleInstance->setRelatedList($relModuleInstance, "$label", $actions, "$relatedlistnode->function"); 815 } 816 return $relModuleInstance; 817 } 818 819 /** 820 * Import custom links of the module. 821 * @access private 822 */ 823 function import_CustomLinks($modulenode, $moduleInstance) { 824 if(empty($modulenode->customlinks) || empty($modulenode->customlinks->customlink)) return; 825 826 foreach($modulenode->customlinks->customlink as $customlinknode) { 827 $handlerInfo = null; 828 if(!empty($customlinknode->handler_path)) { 829 $handlerInfo = array(); 830 $handlerInfo = array("$customlinknode->handler_path", 831 "$customlinknode->handler_class", 832 "$customlinknode->handler"); 833 } 834 $moduleInstance->addLink( 835 "$customlinknode->linktype", 836 "$customlinknode->linklabel", 837 "$customlinknode->linkurl", 838 "$customlinknode->linkicon", 839 "$customlinknode->sequence", 840 $handlerInfo 841 ); 842 } 843 } 844 845 /** 846 * Import cron jobs of the module. 847 * @access private 848 */ 849 function import_CronTasks($modulenode){ 850 if(empty($modulenode->crons) || empty($modulenode->crons->cron)) return; 851 foreach ($modulenode->crons->cron as $cronTask){ 852 if(empty($cronTask->status)){ 853 $cronTask->status = Vtiger_Cron::$STATUS_DISABLED; 854 } else { 855 $cronTask->status = Vtiger_Cron::$STATUS_ENABLED; 856 } 857 if((empty($cronTask->sequence))){ 858 $cronTask->sequence=Vtiger_Cron::nextSequence(); 859 } 860 Vtiger_Cron::register("$cronTask->name","$cronTask->handler", "$cronTask->frequency", "$modulenode->name","$cronTask->status","$cronTask->sequence","$cronTask->description"); 861 } 862 } 863 } 864 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:08:37 2014 | Cross-referenced by PHPXref 0.7.1 |