Example #1
0
 /**
  * Initialize Export
  * @access private
  */
 function __initExport($layoutName)
 {
     // Security check to ensure file is withing the web folder.
     Vtiger_Utils::checkFileAccessForInclusion("layouts/{$layoutName}/skins/vtiger/style.less");
     $this->_export_modulexml_file = fopen($this->__getManifestFilePath(), 'w');
     $this->__write("<?xml version='1.0'?>\n");
 }
Example #2
0
    function undo($moduleName, $userId)
    {
        $adb = PearDatabase::getInstance();
        if (Vtiger_Utils::CheckTable($this->tableName)) {
            $result = $adb->pquery('UPDATE vtiger_crmentity SET deleted=1 WHERE crmid IN
								(SELECT crmid FROM ' . $this->tableName . ' WHERE userid = ? AND entitytype = ?)', array($userId, $moduleName));
            return $adb->getAffectedRowCount($result);
        }
    }
Example #3
0
 public function delete()
 {
     $adb = PearDatabase::getInstance();
     parent::delete();
     $fld_module = $this->getModuleName();
     $id = $this->getId();
     $uitype = $this->get('uitype');
     $typeofdata = $this->get('typeofdata');
     $fieldname = $this->getName();
     $oldfieldlabel = $this->get('label');
     $tablename = $this->get('table');
     $columnname = $this->get('column');
     $fieldtype = explode("~", $typeofdata);
     $tabId = $this->getModuleId();
     $focus = CRMEntity::getInstance($fld_module);
     $deletecolumnname = $tablename . ":" . $columnname . ":" . $fieldname . ":" . $fld_module . "_" . str_replace(" ", "_", $oldfieldlabel) . ":" . $fieldtype[0];
     $column_cvstdfilter = $tablename . ":" . $columnname . ":" . $fieldname . ":" . $fld_module . "_" . str_replace(" ", "_", $oldfieldlabel);
     $select_columnname = $tablename . ":" . $columnname . ":" . $fld_module . "_" . str_replace(" ", "_", $oldfieldlabel) . ":" . $fieldname . ":" . $fieldtype[0];
     $reportsummary_column = $tablename . ":" . $columnname . ":" . str_replace(" ", "_", $oldfieldlabel);
     if ($tablename != 'vtiger_crmentity') {
         $dbquery = 'alter table ' . $adb->quote($tablename, false) . ' drop column ' . $adb->quote($columnname, false);
         $adb->pquery($dbquery, array());
     }
     //we have to remove the entries in customview and report related tables which have this field ($colName)
     $adb->pquery('delete from vtiger_cvcolumnlist where columnname = ? ', array($deletecolumnname));
     $adb->pquery('delete from vtiger_cvstdfilter where columnname = ?', array($column_cvstdfilter));
     $adb->pquery('delete from vtiger_cvadvfilter where columnname = ?', array($deletecolumnname));
     $adb->pquery('delete from vtiger_selectcolumn where columnname = ?', array($select_columnname));
     $adb->pquery('delete from vtiger_relcriteria where columnname = ?', array($select_columnname));
     $adb->pquery('delete from vtiger_reportsortcol where columnname = ?', array($select_columnname));
     $adb->pquery('delete from vtiger_reportdatefilter where datecolumnname = ?', array($column_cvstdfilter));
     $adb->pquery('delete from vtiger_reportsummary where columnname like ?', array('%' . $reportsummary_column . '%'));
     //Deleting from convert lead mapping vtiger_table- Jaguar
     if ($fld_module == 'Leads') {
         $deletequery = 'delete from vtiger_convertleadmapping where leadfid=?';
         $adb->pquery($deletequery, array($id));
     } elseif ($fld_module == 'Accounts' || $fld_module == 'Contacts') {
         $map_del_id = array('Accounts' => 'accountfid', 'Contacts' => 'contactfid');
         $map_del_q = 'update vtiger_convertleadmapping set ' . $map_del_id[$fld_module] . '=0 where ' . $map_del_id[$fld_module] . '=?';
         $adb->pquery($map_del_q, array($id));
     }
     //HANDLE HERE - we have to remove the table for other picklist type values which are text area and multiselect combo box
     if ($this->getFieldDataType() == 'picklist' || $this->getFieldDataType() == 'multipicklist') {
         $result = $adb->pquery('SELECT * FROM `vtiger_field` WHERE `columnname` = ? AND `uitype` IN (?,?,?);', [$columnname, 15, 16, 33]);
         if (!$adb->num_rows($result)) {
             $adb->query('drop table vtiger_' . $columnname);
             //To Delete Sequence Table
             if (Vtiger_Utils::CheckTable('vtiger_' . $columnname . '_seq')) {
                 $adb->query('drop table vtiger_' . $columnname . '_seq');
             }
             $adb->pquery('delete from vtiger_picklist where name=? ', array($columnname));
         }
         $adb->pquery('delete from vtiger_picklist_dependency where `tabid` = ? AND (sourcefield=? or targetfield=?)', array($tabId, $columnname, $columnname));
     }
 }
Example #4
0
 /**
  * Handle event registration for module
  * @param Vtiger_Module Instance of the module to use
  * @param String Name of the Event like vtiger.entity.aftersave, vtiger.entity.beforesave
  * @param String Name of the Handler class (should extend VTEventHandler)
  * @param String File path which has Handler class definition
  * @param String Condition for the event to trigger (default blank)
  */
 static function register($moduleInstance, $eventname, $classname, $filename, $condition = '', $dependent = '[]')
 {
     // Security check on fileaccess, don't die if it fails
     if (Vtiger_Utils::checkFileAccess($filename, false)) {
         $adb = PearDatabase::getInstance();
         $eventsManager = new VTEventsManager($adb);
         $eventsManager->registerHandler($eventname, $filename, $classname, $condition, $dependent);
         $eventsManager->setModuleForHandler($moduleInstance->name, $classname);
         self::log("Registering Event {$eventname} with [{$filename}] {$classname} ... DONE");
     }
 }
Example #5
0
 public static function getImportInfoById($importId)
 {
     $db = PearDatabase::getInstance();
     if (Vtiger_Utils::CheckTable('vtiger_import_queue')) {
         $queueResult = $db->pquery('SELECT * FROM vtiger_import_queue WHERE importid=?', array($importId));
         if ($queueResult && $db->num_rows($queueResult) > 0) {
             $rowData = $db->raw_query_result_rowdata($queueResult, 0);
             return self::getImportInfoFromResult($rowData);
         }
     }
     return null;
 }
 public static function isLockedForModule($module)
 {
     $adb = PearDatabase::getInstance();
     if (Vtiger_Utils::CheckTable('vtiger_import_locks')) {
         $lockResult = $adb->pquery('SELECT * FROM vtiger_import_locks WHERE tabid=?', array(getTabid($module)));
         if ($lockResult && $adb->num_rows($lockResult) > 0) {
             $lockInfo = $adb->query_result_rowdata($lockResult, 0);
             return $lockInfo;
         }
     }
     return null;
 }
Example #7
0
 public static function getInstance($value)
 {
     $db = PearDatabase::getInstance();
     if (Vtiger_Utils::isNumber($value)) {
         $sql = 'SELECT * FROM vtiger_org_share_action_mapping WHERE share_action_id = ?';
     } else {
         $sql = 'SELECT * FROM vtiger_org_share_action_mapping WHERE share_action_name = ?';
     }
     $params = array($value);
     $result = $db->pquery($sql, $params);
     if ($db->num_rows($result) > 0) {
         return self::getInstanceFromQResult($result);
     }
     return null;
 }
Example #8
0
 public static function getInstance($id)
 {
     $db = PearDatabase::getInstance();
     if (Vtiger_Utils::isNumber($id)) {
         $query = 'SELECT * FROM ' . Settings_Currency_Module_Model::tableName . ' WHERE id=?';
     } else {
         $query = 'SELECT * FROM ' . Settings_Currency_Module_Model::tableName . ' WHERE currency_name=?';
     }
     $params = array($id);
     $result = $db->pquery($query, $params);
     if ($db->num_rows($result) > 0) {
         $instance = new self();
         $row = $db->query_result_rowdata($result, 0);
         $instance->setData($row);
     }
     return $instance;
 }
Example #9
0
 function registerCustomWebservices($operations)
 {
     global $adb;
     foreach ($operations as $operation_name => $operation_info) {
         $checkres = $adb->pquery("SELECT operationid FROM vtiger_ws_operation WHERE name=?", array($operation_name));
         if ($checkres && $adb->num_rows($checkres) < 1) {
             $operation_id = $adb->getUniqueId('vtiger_ws_operation');
             $operation_res = $adb->pquery("INSERT INTO vtiger_ws_operation (operationid, name, handler_path, handler_method, type, prelogin) \n\t\t\t\t\tVALUES (?,?,?,?,?,?)", array($operation_id, $operation_name, $operation_info['file'], $operation_info['handler'], $operation_info['reqtype'], $operation_info['prelogin']));
             $operation_parameters = $operation_info['parameters'];
             $parameter_index = 0;
             foreach ($operation_parameters as $parameter_name => $parameter_type) {
                 $adb->pquery("INSERT INTO vtiger_ws_operation_parameters (operationid, name, type, sequence) \n\t\t\t\t\t\tVALUES(?,?,?,?)", array($operation_id, $parameter_name, $parameter_type, $parameter_index + 1));
                 ++$parameter_index;
             }
             Vtiger_Utils::Log("Opearation {$operation_name} enabled successfully.");
         } else {
             Vtiger_Utils::Log("Operation {$operation_name} already exists.");
         }
     }
 }
Example #10
0
 /**
  * Initialize Layout Schema
  * @access private
  */
 static function __initSchema()
 {
     $hastable = Vtiger_Utils::CheckTable(self::TABLENAME);
     if (!$hastable) {
         Vtiger_Utils::CreateTable(self::TABLENAME, '(id INT NOT NULL PRIMARY KEY,
                         name VARCHAR(50), label VARCHAR(30), lastupdated DATETIME, isdefault INT(1), active INT(1))', true);
     }
 }
Example #11
0
 /**
  * Import Tables of the module
  * @access private
  */
 function import_Tables($modulenode)
 {
     if (empty($modulenode->tables) || empty($modulenode->tables->table)) {
         return;
     }
     /**
      * Record the changes in schema file
      */
     $schemafile = @fopen("modules/{$modulenode->name}/schema.xml", 'w');
     if ($schemafile) {
         fwrite($schemafile, "<?xml version='1.0'?>\n");
         fwrite($schemafile, "<schema>\n");
         fwrite($schemafile, "\t<tables>\n");
     }
     // Import the table via queries
     foreach ($modulenode->tables->table as $tablenode) {
         $tablename = $tablenode->name;
         $tablesql = "{$tablenode->sql}";
         // Convert to string format
         // Save the information in the schema file.
         if ($schemafile) {
             fwrite($schemafile, "\t\t<table>\n");
             fwrite($schemafile, "\t\t\t<name>{$tablename}</name>\n");
             fwrite($schemafile, "\t\t\t<sql><![CDATA[{$tablesql}]]></sql>\n");
             fwrite($schemafile, "\t\t</table>\n");
         }
         // Avoid executing SQL that will DELETE or DROP table data
         if (Vtiger_Utils::IsCreateSql($tablesql)) {
             if (!Vtiger_Utils::checkTable($tablename)) {
                 self::log("SQL: {$tablesql} ... ", false);
                 Vtiger_Utils::ExecuteQuery($tablesql);
                 self::log("DONE");
             }
         } else {
             if (Vtiger_Utils::IsDestructiveSql($tablesql)) {
                 self::log("SQL: {$tablesql} ... SKIPPED");
             } else {
                 self::log("SQL: {$tablesql} ... ", false);
                 Vtiger_Utils::ExecuteQuery($tablesql);
                 self::log("DONE");
             }
         }
     }
     if ($schemafile) {
         fwrite($schemafile, "\t</tables>\n");
         fwrite($schemafile, "</schema>\n");
         fclose($schemafile);
     }
 }
 /**
  * Handle migration of the module
  * @access private
  */
 function handle_Migration($modulenode, $moduleInstance)
 {
     // TODO Handle module migration SQL
     $this->parse_Migration($modulenode);
     $cur_version = $moduleInstance->version;
     foreach ($this->_migrations as $migversion => $migrationnode) {
         // Perform migration only for higher version than current
         if (version_compare($cur_version, $migversion, '<')) {
             self::log("Migrating to {$migversion} ... STARTED");
             if (!empty($migrationnode->tables) && !empty($migrationnode->tables->table)) {
                 foreach ($migrationnode->tables->table as $tablenode) {
                     $tablename = $tablenode->name;
                     $tablesql = "{$tablenode->sql}";
                     // Convert to string
                     // Skip SQL which are destructive
                     if (Vtiger_Utils::IsDestructiveSql($tablesql)) {
                         self::log("SQL: {$tablesql} ... SKIPPED");
                     } else {
                         // Supress any SQL query failures
                         self::log("SQL: {$tablesql} ... ", false);
                         Vtiger_Utils::ExecuteQuery($tablesql, true);
                         self::log("DONE");
                     }
                 }
             }
             self::log("Migrating to {$migversion} ... DONE");
         }
     }
 }
Example #13
0
    /**
     * Initialize the schema.
     */
    protected static function initializeSchema()
    {
        if (!self::$schemaInitialized) {
            if (!Vtiger_Utils::CheckTable('vtiger_cron_task')) {
                Vtiger_Utils::CreateTable('vtiger_cron_task', '(id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
					name VARCHAR(100) UNIQUE KEY, handler_file VARCHAR(100) UNIQUE KEY,
					frequency int, laststart int(11) unsigned, lastend int(11) unsigned, status int,module VARCHAR(100),
                                        sequence int,description TEXT )', true);
            }
            self::$schemaInitialized = true;
        }
    }
Example #14
0
 /**
  * Import Tables of the module
  * @access private
  */
 function import_Tables($modulenode)
 {
     if (empty($modulenode->tables) || empty($modulenode->tables->table)) {
         return;
     }
     $adb = PearDatabase::getInstance();
     $adb->query('SET FOREIGN_KEY_CHECKS = 0;');
     /**
      * Record the changes in schema file
      */
     if (file_exists("modules/{$modulenode->name}")) {
         $fileToOpen = "modules/{$modulenode->name}/schema.xml";
     } else {
         if (file_exists("modules/Settings/{$modulenode->name}")) {
             $fileToOpen = "modules/Settings/{$modulenode->name}/schema.xml";
         }
     }
     $schemafile = fopen($fileToOpen, 'w');
     if ($schemafile) {
         fwrite($schemafile, "<?xml version='1.0'?>\n");
         fwrite($schemafile, "<schema>\n");
         fwrite($schemafile, "\t<tables>\n");
     }
     // Import the table via queries
     foreach ($modulenode->tables->table as $tablenode) {
         $tablename = $tablenode->name;
         $tablesql = "{$tablenode->sql}";
         // Convert to string format
         // Save the information in the schema file.
         fwrite($schemafile, "\t\t<table>\n");
         fwrite($schemafile, "\t\t\t<name>{$tablename}</name>\n");
         fwrite($schemafile, "\t\t\t<sql><![CDATA[{$tablesql}]]></sql>\n");
         fwrite($schemafile, "\t\t</table>\n");
         // Avoid executing SQL that will DELETE or DROP table data
         if (Vtiger_Utils::IsCreateSql($tablesql)) {
             if (!Vtiger_Utils::checkTable($tablename)) {
                 self::log("SQL: {$tablesql} ... ", false);
                 Vtiger_Utils::ExecuteQuery($tablesql);
                 self::log("DONE");
             }
         } else {
             if (Vtiger_Utils::IsDestructiveSql($tablesql)) {
                 self::log("SQL: {$tablesql} ... SKIPPED");
             } else {
                 self::log("SQL: {$tablesql} ... ", false);
                 Vtiger_Utils::ExecuteQuery($tablesql);
                 self::log("DONE");
             }
         }
     }
     if ($schemafile) {
         fwrite($schemafile, "\t</tables>\n");
         fwrite($schemafile, "</schema>\n");
         fclose($schemafile);
     }
     $adb->query('SET FOREIGN_KEY_CHECKS = 1;');
 }
 /**
  * Get all the language information
  * @param Boolean true to include in-active languages also, false (default)
  */
 static function getAll($includeInActive = false)
 {
     global $adb;
     $hastable = Vtiger_Utils::CheckTable(self::TABLENAME);
     $languageinfo = array();
     if ($hastable) {
         if ($includeInActive) {
             $result = $adb->pquery('SELECT * FROM ' . self::TABLENAME, array());
         } else {
             $result = $adb->pquery('SELECT * FROM ' . self::TABLENAME . ' WHERE active=?', array(1));
         }
         for ($index = 0; $index < $adb->num_rows($result); ++$index) {
             $resultrow = $adb->fetch_array($result);
             $prefix = $resultrow['prefix'];
             $label = $resultrow['label'];
             $languageinfo[$prefix] = $label;
         }
     } else {
         global $languages;
         foreach ($languages as $prefix => $label) {
             $languageinfo[$prefix] = $label;
         }
     }
     // SalesPlatform.ru begin Set ru_ru to first position
     if ($languageinfo['ru_ru']) {
         $ruLabel = $languageinfo['ru_ru'];
         unset($languageinfo['ru_ru']);
         $languageinfo = array_merge(array('ru_ru' => $ruLabel), $languageinfo);
     }
     // SalesPlatform.ru end
     return $languageinfo;
 }
Example #16
0
 public static function isUserImportBlocked($user)
 {
     $adb = PearDatabase::getInstance();
     $tableName = self::getDbTableName($user);
     if (Vtiger_Utils::CheckTable($tableName)) {
         $result = $adb->query('SELECT 1 FROM ' . $tableName . ' WHERE temp_status = ' . Import_Data_Action::$IMPORT_RECORD_NONE);
         if ($adb->num_rows($result) > 0) {
             return true;
         }
     }
     return false;
 }
Example #17
0
 public function getPicklistId($fieldName, $value)
 {
     global $log, $adb;
     $log->debug("Entering YetiForceUpdate::getPicklistId(" . $fieldName . ',' . $value . ") method ...");
     if (Vtiger_Utils::CheckTable('vtiger_' . $fieldName)) {
         $sql = 'SELECT * FROM vtiger_' . $fieldName . ' WHERE ' . $fieldName . ' = ? ;';
         $result = $adb->pquery($sql, array($value));
         if ($adb->num_rows($result) > 0) {
             $log->debug("Exiting YetiForceUpdate::getPicklistId() method ...");
             return $adb->query_result($result, 0, 'picklist_valueid');
         }
     }
     $log->debug("Exiting YetiForceUpdate::getPicklistId() method ...");
     return false;
 }
Example #18
0
 public static function initializeSchema()
 {
     if (!Vtiger_Utils::CheckTable('vtiger_google_oauth')) {
         Vtiger_Utils::CreateTable('vtiger_google_oauth', '(service varchar(64),request_token text,access_token text,userid int)', true);
     }
 }
Example #19
0
 /**
  * Initialize Language Schema
  * @access private
  */
 static function __initSchema()
 {
     $hastable = Vtiger_Utils::CheckTable(self::TABLENAME);
     if (!$hastable) {
         Vtiger_Utils::CreateTable(self::TABLENAME, '(id INT NOT NULL PRIMARY KEY,
                         name VARCHAR(50), label VARCHAR(30), lastupdated DATETIME, isdefault INT(1), active INT(1))', true);
         global $languages, $adb;
         foreach ($languages as $langkey => $langlabel) {
             $uniqueid = self::__getUniqueId();
             $adb->pquery('INSERT INTO ' . self::TABLENAME . '(id,name,label,lastupdated,isdefault,active) VALUES(?,?,?,?,?,?)', array($uniqueid, $langlabel, $langlabel, date('Y-m-d H:i:s', time()), 0, 1));
         }
     }
 }
Example #20
0
 /**
  * Creating a new field
  * @param string $type
  * @param array $params
  * @return array/false
  */
 public function addField($type, $params)
 {
     $adb = PearDatabase::getInstance();
     $inventoryClassName = Vtiger_Loader::getComponentClassName('InventoryField', $type, $this->get('module'));
     $instance = new $inventoryClassName();
     $table = $this->getTableName();
     $columnName = $instance->getColumnName();
     $label = $instance->getDefaultLabel();
     $defaultValue = $instance->getDefaultValue();
     $colSpan = $instance->getColSpan();
     if (!$instance->isOnlyOne()) {
         $id = $this->getUniqueID($instance);
         $columnName = $columnName . $id;
     }
     if (isset($params['label'])) {
         $label = $params['label'];
     }
     if (isset($params['defaultValue'])) {
         $defaultValue = $params['defaultValue'];
     }
     if (isset($params['colSpan'])) {
         $colSpan = $params['colSpan'];
     }
     Vtiger_Utils::AddColumn($table, $columnName, $instance->getDBType());
     foreach ($instance->getCustomColumn() as $column => $criteria) {
         Vtiger_Utils::AddColumn($table, $column, $criteria);
     }
     $result = $adb->query("SELECT MAX(sequence) AS max FROM " . $this->getTableName('fields'));
     $sequence = (int) $adb->getSingleValue($result) + 1;
     return $adb->insert($this->getTableName('fields'), ['columnname' => $columnName, 'label' => $label, 'invtype' => $instance->getName(), 'defaultvalue' => $defaultValue, 'sequence' => $sequence, 'block' => $params['block'], 'displaytype' => $params['displayType'], 'params' => $params['params'], 'colspan' => $colSpan]);
 }
Example #21
0
 /**
  * Remove relation between the field and modules (UIType 10)
  * @param Array List of module names
  */
 function unsetRelatedModules($moduleNames)
 {
     global $adb;
     foreach ($moduleNames as $relmodule) {
         $adb->pquery('DELETE FROM vtiger_fieldmodulerel WHERE fieldid=? AND module=? AND relmodule = ?', array($this->id, $this->getModuleName(), $relmodule));
         Vtiger_Utils::Log("Unsetting {$this->name} relation with {$relmodule} ... DONE");
     }
     return true;
 }
Example #22
0
 /**
  * Get instance by filterid or filtername
  * @param mixed filterid or filtername
  * @param Vtiger_Module Instance of the module to use when filtername is used
  */
 static function getInstance($value, $moduleInstance = false)
 {
     global $adb;
     $instance = false;
     $query = false;
     $queryParams = false;
     if (Vtiger_Utils::isNumber($value)) {
         $query = "SELECT * FROM vtiger_customview WHERE cvid=?";
         $queryParams = array($value);
     } else {
         $query = "SELECT * FROM vtiger_customview WHERE viewname=? AND entitytype=?";
         $queryParams = array($value, $moduleInstance->name);
     }
     $result = $adb->pquery($query, $queryParams);
     if ($adb->num_rows($result)) {
         $instance = new self();
         $instance->initialize($adb->fetch_array($result), $moduleInstance);
     }
     return $instance;
 }
Example #23
0
 /**
  * Helper function to log messages
  * @param String Message to log
  * @param Boolean true appends linebreak, false to avoid it
  * @access private
  */
 static function log($message, $delimit = true)
 {
     Vtiger_Utils::Log($message, $delimit);
 }
Example #24
0
 /**
  * Static Function to get the instance of Vtiger Module Model for the given id or name
  * @param mixed id or name of the module
  */
 public static function getInstance($value)
 {
     $db = PearDatabase::getInstance();
     $instance = false;
     $query = false;
     if (Vtiger_Utils::isNumber($value)) {
         $query = 'SELECT * FROM vtiger_def_org_share INNER JOIN vtiger_tab ON vtiger_tab.tabid = vtiger_def_org_share.tabid WHERE vtiger_tab.tabid=?';
     } else {
         $query = 'SELECT * FROM vtiger_def_org_share INNER JOIN vtiger_tab ON vtiger_tab.tabid = vtiger_def_org_share.tabid WHERE name=?';
     }
     $result = $db->pquery($query, array($value));
     if ($db->num_rows($result)) {
         $row = $db->query_result_rowdata($result, 0);
         $instance = new Settings_SharingAccess_Module_Model();
         $instance->initialize($row);
         $instance->set('permission', $row['permission']);
         $instance->set('editstatus', $row['editstatus']);
     }
     return $instance;
 }
 /**
  * Get instance of block
  * @param mixed block id or block label
  * @param Vtiger_Module Instance of the module if block label is passed
  */
 static function getInstance($value, $moduleInstance = false)
 {
     global $adb;
     $cache = Vtiger_Cache::getInstance();
     if ($moduleInstance && $cache->getBlockInstance($value, $moduleInstance->id)) {
         return $cache->getBlockInstance($value, $moduleInstance->id);
     } else {
         $instance = false;
         $query = false;
         $queryParams = false;
         if (Vtiger_Utils::isNumber($value)) {
             $query = "SELECT * FROM vtiger_blocks WHERE blockid=?";
             $queryParams = array($value);
         } else {
             $query = "SELECT * FROM vtiger_blocks WHERE blocklabel=? AND tabid=?";
             $queryParams = array($value, $moduleInstance->id);
         }
         $result = $adb->pquery($query, $queryParams);
         if ($adb->num_rows($result)) {
             $instance = new self();
             $instance->initialize($adb->fetch_array($result), $moduleInstance);
         }
         $cache->setBlockInstance($value, $instance->module->id, $instance);
         return $instance;
     }
 }
Example #26
0
/** Function to transfer the ownership of records owned by a particular group to the specified group
 * @param $groupId -- Group Id of the group which's record ownership has to be transferred:: Type integer
 * @param $transferId --  Id of the group/user to which record ownership is to be transferred:: Type integer
 * @param $transferType -- It can have only two values namely 'Groups' or 'Users'. This determines whether the owneship is to be transferred to a group or user :: Type varchar
 */
function tranferGroupOwnership($groupId, $transferId)
{
    global $log;
    $log->debug("Entering tranferGroupOwnership(" . $groupId . ") method ...");
    global $adb;
    $query = "update vtiger_crmentity set smownerid=? where smownerid=?";
    $params = array($transferId, $groupId);
    $adb->pquery($query, $params);
    if (Vtiger_Utils::CheckTable('vtiger_customerportal_prefs')) {
        $query = 'UPDATE vtiger_customerportal_prefs SET prefvalue = ? WHERE prefkey = ? AND prefvalue = ?';
        $params = array($transferId, 'defaultassignee', $groupId);
        $adb->pquery($query, $params);
        $query = 'UPDATE vtiger_customerportal_prefs SET prefvalue = ? WHERE prefkey = ? AND prefvalue = ?';
        $params = array($transferId, 'userid', $groupId);
        $adb->pquery($query, $params);
    }
    $log->debug("Exiting tranferGroupOwnership method ...");
}
Example #27
0
 public static function runScheduledReports()
 {
     vimport('~~modules/com_vtiger_workflow/VTWorkflowUtils.php');
     $util = new VTWorkflowUtils();
     $util->adminUser();
     $currentModule = vglobal('currentModule');
     $current_language = vglobal('current_language');
     if (empty($currentModule)) {
         $currentModule = 'Reports';
     }
     if (empty($current_language)) {
         vglobal('current_language', 'en_us');
     }
     $scheduledReports = self::getScheduledReports();
     foreach ($scheduledReports as $scheduledReport) {
         $status = $scheduledReport->sendEmail();
         Vtiger_Utils::ModuleLog('ScheduleReprot Send Mail Status ', $status);
         if ($status) {
             $scheduledReport->updateNextTriggerTime();
         }
     }
     $util->revertUser();
     return $status;
 }
Example #28
0
function vtws_transferOwnership($ownerId, $newOwnerId, $delete = true)
{
    $db = PearDatabase::getInstance();
    //Updating the smcreatorid,smownerid, modifiedby in vtiger_crmentity
    $sql = "update vtiger_crmentity set smcreatorid=? where smcreatorid=?";
    $db->pquery($sql, array($newOwnerId, $ownerId));
    $sql = "update vtiger_crmentity set smownerid=? where smownerid=?";
    $db->pquery($sql, array($newOwnerId, $ownerId));
    $sql = "update vtiger_crmentity set modifiedby=? where modifiedby=?";
    $db->pquery($sql, array($newOwnerId, $ownerId));
    //deleting from vtiger_tracker
    if ($delete) {
        $sql = "delete from vtiger_tracker where user_id=?";
        $db->pquery($sql, array($ownerId));
    }
    //updating the vtiger_import_maps
    $sql = "update vtiger_import_maps set assigned_user_id=? where assigned_user_id=?";
    $db->pquery($sql, array($newOwnerId, $ownerId));
    if (Vtiger_Utils::CheckTable('vtiger_customerportal_prefs')) {
        $query = 'UPDATE vtiger_customerportal_prefs SET prefvalue = ? WHERE prefkey = ? AND prefvalue = ?';
        $params = array($newOwnerId, 'defaultassignee', $ownerId);
        $db->pquery($query, $params);
        $query = 'UPDATE vtiger_customerportal_prefs SET prefvalue = ? WHERE prefkey = ? AND prefvalue = ?';
        $params = array($newOwnerId, 'userid', $ownerId);
        $db->pquery($query, $params);
    }
    //delete from vtiger_homestuff
    if ($delete) {
        $sql = "delete from vtiger_homestuff where userid=?";
        $db->pquery($sql, array($ownerId));
    }
    //delete from vtiger_users to group vtiger_table
    if ($delete) {
        $sql = "delete from vtiger_user2role where userid=?";
        $db->pquery($sql, array($ownerId));
    }
    //delete from vtiger_users to vtiger_role vtiger_table
    if ($delete) {
        $sql = "delete from vtiger_users2group where userid=?";
        $db->pquery($sql, array($ownerId));
    }
    $sql = "select tabid,fieldname,tablename,columnname from vtiger_field left join " . "vtiger_fieldmodulerel on vtiger_field.fieldid=vtiger_fieldmodulerel.fieldid where uitype " . "in (52,53,77,101) or (uitype=10 and relmodule='Users')";
    $result = $db->pquery($sql, array());
    $it = new SqlResultIterator($db, $result);
    $columnList = array();
    foreach ($it as $row) {
        $column = $row->tablename . '.' . $row->columnname;
        if (!in_array($column, $columnList)) {
            $columnList[] = $column;
            $sql = "update {$row->tablename} set {$row->columnname}=? where {$row->columnname}=?";
            $db->pquery($sql, array($newOwnerId, $ownerId));
        }
    }
}
Example #29
0
 /**
  * Get instance of the module class.
  * @param String Module name
  */
 static function getClassInstance($modulename)
 {
     if ($modulename == 'Calendar') {
         $modulename = 'Activity';
     }
     $instance = false;
     $filepath = "modules/{$modulename}/{$modulename}.php";
     if (Vtiger_Utils::checkFileAccessForInclusion($filepath, false)) {
         checkFileAccessForInclusion($filepath);
         include_once $filepath;
         if (class_exists($modulename)) {
             $instance = new $modulename();
         }
     }
     return $instance;
 }
Example #30
0
 /**
  *
  * @param String $packagepath - path to the package file.
  * @return Array
  */
 static function getOptionalModuleDetails($package, $optionalModulesInfo)
 {
     global $optionalModuleStrings;
     $moduleUpdateVersion = $package->getVersion();
     $moduleForVtigerVersion = $package->getDependentVtigerVersion();
     $moduleMaxVtigerVersion = $package->getDependentMaxVtigerVersion();
     if ($package->isLanguageType()) {
         $type = 'language';
     } else {
         $type = 'module';
     }
     $moduleDetails = null;
     $moduleName = $package->getModuleName();
     if ($moduleName != null) {
         $moduleDetails = array();
         $moduleDetails['description'] = $optionalModuleStrings[$moduleName . '_description'];
         if (Vtiger_Version::check($moduleForVtigerVersion, '>=') && Vtiger_Version::check($moduleMaxVtigerVersion, '<')) {
             $moduleDetails['selected'] = true;
             $moduleDetails['enabled'] = true;
         } else {
             $moduleDetails['selected'] = false;
             $moduleDetails['enabled'] = false;
         }
         $migrationAction = 'install';
         if (!$package->isLanguageType()) {
             $moduleInstance = null;
             if (Vtiger_Utils::checkTable('vtiger_tab')) {
                 $moduleInstance = Vtiger_Module::getInstance($moduleName);
             }
             if ($moduleInstance) {
                 $migrationAction = 'update';
                 if (version_compare($moduleUpdateVersion, $moduleInstance->version, '>=')) {
                     $moduleDetails['enabled'] = false;
                 }
             }
         } else {
             if (Vtiger_Utils::CheckTable(Vtiger_Language::TABLENAME)) {
                 $languageList = array_keys(Vtiger_Language::getAll());
                 $prefix = $package->getPrefix();
                 if (in_array($prefix, $languageList)) {
                     $migrationAction = 'update';
                 }
             }
         }
         $optionalModulesInfo[$migrationAction][$type][$moduleName] = $moduleDetails;
     }
     return $optionalModulesInfo;
 }