[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/vtlib/Vtiger/ -> LayoutExport.php (source)

   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/Package.php');
  11  
  12  /**
  13   * Provides API to package vtiger CRM language files.
  14   * @package vtlib
  15   */
  16  class Vtiger_LayoutExport extends Vtiger_Package {
  17      const TABLENAME = 'vtiger_layout';
  18  
  19      /**
  20       * Constructor
  21       */
  22      function __construct() {
  23              parent::__construct();
  24      }
  25  
  26      /**
  27       * Generate unique id for insertion
  28       * @access private
  29       */
  30      static function __getUniqueId() {
  31              global $adb;
  32              return $adb->getUniqueID(self::TABLENAME);
  33      }
  34  
  35      /**
  36       * Initialize Export
  37       * @access private
  38       */
  39      function __initExport($layoutName) {
  40              // Security check to ensure file is withing the web folder.
  41              Vtiger_Utils::checkFileAccessForInclusion("layouts/$layoutName/skins/vtiger/style.less");
  42  
  43              $this->_export_modulexml_file = fopen($this->__getManifestFilePath(), 'w');
  44              $this->__write("<?xml version='1.0'?>\n");
  45      }
  46  
  47      /**
  48       * Export Module as a zip file.
  49       * @param Vtiger_Module Instance of module
  50       * @param Path Output directory path
  51       * @param String Zipfilename to use
  52       * @param Boolean True for sending the output as download
  53       */
  54      function export($layoutName, $todir='', $zipfilename='', $directDownload=false) {
  55              $this->__initExport($layoutName);
  56  
  57              // Call layout export function
  58              $this->export_Layout($layoutName);
  59  
  60              $this->__finishExport();
  61  
  62              // Export as Zip
  63              if($zipfilename == '') $zipfilename = "$layoutName-" . date('YmdHis') . ".zip";
  64              $zipfilename = "$this->_export_tmpdir/$zipfilename";
  65  
  66              $zip = new Vtiger_Zip($zipfilename);
  67  
  68              // Add manifest file
  69              $zip->addFile($this->__getManifestFilePath(), "manifest.xml");
  70  
  71              // Copy module directory
  72              $zip->copyDirectoryFromDisk("layouts/$layoutName");
  73  
  74              $zip->save();
  75  
  76              if($todir) {
  77                      copy($zipfilename, $todir);
  78              }
  79              
  80              if($directDownload) {
  81                      $zip->forceDownload($zipfilename);
  82                      unlink($zipfilename);
  83              }
  84              $this->__cleanupExport();
  85      }
  86  
  87      /**
  88       * Export Language Handler
  89       * @access private
  90       */
  91      function export_Layout($layoutName) {
  92              global $adb;
  93  
  94              $sqlresult = $adb->pquery("SELECT * FROM vtiger_layout WHERE name = ?", array($layoutName));
  95              $layoutresultrow = $adb->fetch_array($sqlresult);
  96  
  97              $layoutname  = decode_html($layoutresultrow['name']);
  98              $layoutlabel = decode_html($layoutresultrow['label']);
  99  
 100              $this->openNode('module');
 101              $this->outputNode(date('Y-m-d H:i:s'),'exporttime');
 102              $this->outputNode($layoutname, 'name');
 103              $this->outputNode($layoutlabel, 'label');
 104  
 105              $this->outputNode('layout', 'type');
 106  
 107              // Export dependency information
 108              $this->export_Dependencies();
 109  
 110              $this->closeNode('module');
 111      }
 112  
 113      /**
 114       * Export vtiger dependencies
 115       * @access private
 116       */
 117      function export_Dependencies() {
 118              global $vtiger_current_version, $adb;
 119  
 120              $vtigerMinVersion = $vtiger_current_version;
 121              $vtigerMaxVersion = false;
 122  
 123              $this->openNode('dependencies');
 124              $this->outputNode($vtigerMinVersion, 'vtiger_version');
 125              if($vtigerMaxVersion !== false)    $this->outputNode($vtigerMaxVersion, 'vtiger_max_version');
 126              $this->closeNode('dependencies');
 127      }
 128  
 129  
 130      /**
 131       * Initialize Language Schema
 132       * @access private
 133       */
 134      static function __initSchema() {
 135              $hastable = Vtiger_Utils::CheckTable(self::TABLENAME);
 136              if(!$hastable) {
 137                      Vtiger_Utils::CreateTable(
 138                              self::TABLENAME,
 139                              '(id INT NOT NULL PRIMARY KEY,
 140                              name VARCHAR(50), label VARCHAR(30), lastupdated DATETIME, isdefault INT(1), active INT(1))',
 141                              true
 142                      );
 143                      global $languages, $adb;
 144                      foreach($languages as $langkey=>$langlabel) {
 145                              $uniqueid = self::__getUniqueId();
 146                              $adb->pquery('INSERT INTO '.self::TABLENAME.'(id,name,label,lastupdated,isdefault,active) VALUES(?,?,?,?,?,?)',
 147                                      Array($uniqueid, $langlabel,$langlabel,date('Y-m-d H:i:s',time()), 0,1));
 148                      }
 149              }
 150      }
 151      
 152      /**
 153       * Register language pack information.
 154       */
 155      static function register($label, $name='', $isdefault=false, $isactive=true, $overrideCore=false) {
 156              self::__initSchema();
 157  
 158              $prefix = trim($prefix);
 159              // We will not allow registering core layouts unless forced
 160              if(strtolower($name) == 'vlayout' && $overrideCore == false) return;
 161  
 162              $useisdefault = ($isdefault)? 1 : 0;
 163              $useisactive  = ($isactive)?  1 : 0;
 164  
 165              global $adb;
 166              $checkres = $adb->pquery('SELECT * FROM '.self::TABLENAME.' WHERE name=?', Array($name));
 167              $datetime = date('Y-m-d H:i:s');
 168              if($adb->num_rows($checkres)) {
 169                      $id = $adb->query_result($checkres, 0, 'id');
 170                      $adb->pquery('UPDATE '.self::TABLENAME.' set label=?, name=?, lastupdated=?, isdefault=?, active=? WHERE id=?',
 171                              Array($label, $name, $datetime, $useisdefault, $useisactive, $id));
 172              } else {
 173                      $uniqueid = self::__getUniqueId();
 174                      $adb->pquery('INSERT INTO '.self::TABLENAME.' (id,name,label,lastupdated,isdefault,active) VALUES(?,?,?,?,?,?)',
 175                              Array($uniqueid, $name, $label, $datetime, $useisdefault, $useisactive));
 176              }
 177              self::log("Registering Language $label [$prefix] ... DONE");        
 178      }
 179  
 180  }


Generated: Fri Nov 28 20:08:37 2014 Cross-referenced by PHPXref 0.7.1