vtlib 文件夹,中间存储了 vTiger 的开发库。

This commit is contained in:
YUCHENG HU 2013-01-30 22:10:16 -05:00
parent e54e866ca0
commit ee2bfb0db6
22 changed files with 2360 additions and 0 deletions

View File

@ -0,0 +1,53 @@
<?php
/*+**********************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
************************************************************************************/
global $current_user, $currentModule;
checkFileAccessForInclusion("modules/$currentModule/$currentModule.php");
require_once("modules/$currentModule/$currentModule.php");
$focus = new $currentModule();
setObjectValuesFromRequest($focus);
$mode = $_REQUEST['mode'];
$record=$_REQUEST['record'];
if($mode) $focus->mode = $mode;
if($record)$focus->id = $record;
if($_REQUEST['assigntype'] == 'U') {
$focus->column_fields['assigned_user_id'] = $_REQUEST['assigned_user_id'];
} elseif($_REQUEST['assigntype'] == 'T') {
$focus->column_fields['assigned_user_id'] = $_REQUEST['assigned_group_id'];
}
$focus->save($currentModule);
$return_id = $focus->id;
$search = vtlib_purify($_REQUEST['search_url']);
$parenttab = getParentTab();
if($_REQUEST['return_module'] != '') {
$return_module = vtlib_purify($_REQUEST['return_module']);
} else {
$return_module = $currentModule;
}
if($_REQUEST['return_action'] != '') {
$return_action = vtlib_purify($_REQUEST['return_action']);
} else {
$return_action = "DetailView";
}
if($_REQUEST['return_id'] != '') {
$return_id = vtlib_purify($_REQUEST['return_id']);
}
header("Location: index.php?action=$return_action&module=$return_module&record=$return_id&parenttab=$parenttab&start=".vtlib_purify($_REQUEST['pagenumber']).$search);
?>

View File

@ -0,0 +1,13 @@
<?php
/*+**********************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
************************************************************************************/
include('modules/Vtiger/Settings.php');
?>

View File

@ -0,0 +1,11 @@
<?php
/*+**********************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
************************************************************************************/
require_once('include/Ajax/TagCloud.php');
?>

View File

@ -0,0 +1,11 @@
<?php
/*+*******************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
*********************************************************************************/
require_once 'modules/Home/UnifiedSearch.php';
?>

View File

@ -0,0 +1,15 @@
<?php
/*+**********************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
************************************************************************************/
global $currentModule;
checkFileAccessForInclusion("modules/$currentModule/ListView.php");
include_once("modules/$currentModule/ListView.php");
?>

View File

@ -0,0 +1,22 @@
<?php
/*+**********************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
************************************************************************************/
$mod_strings = Array(
'ModuleName' => 'Modulname',
'SINGLE_ModuleName' => 'Modulname',
'ModuleName ID' => 'Modulname ID',
'LBL_CUSTOM_INFORMATION' => 'zusätzliche Information',
'LBL_MODULEBLOCK_INFORMATION' => 'ModuleBlock Information',
'ModuleFieldLabel' => 'ModuleFieldLabel Text',
);
?>

View File

@ -0,0 +1,22 @@
<?php
/*+**********************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
************************************************************************************/
$mod_strings = Array(
'ModuleName' => 'Module Name',
'SINGLE_ModuleName' => 'Module Name',
'ModuleName ID' => 'Module Name ID',
'LBL_CUSTOM_INFORMATION' => 'Custom Information',
'LBL_MODULEBLOCK_INFORMATION' => 'ModuleBlock Information',
'ModuleFieldLabel' => 'ModuleFieldLabel Text',
);
?>

View File

@ -0,0 +1,22 @@
<?php
/*+**********************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
************************************************************************************/
$mod_strings = Array(
'ModuleName' => 'Nome Módulo',
'SINGLE_ModuleName' => 'Nome Módulo',
'ModuleName ID' => 'ID Nome Módulo',
'LBL_CUSTOM_INFORMATION' => 'Imformação Customizada',
'LBL_MODULEBLOCK_INFORMATION' => 'Informação Bloco Módulo',
'ModuleFieldLabel' => 'Texto Etiqueta Campo Módulo',
);
?>

View File

@ -0,0 +1,35 @@
<?php
/**
* Copyright (C) 2006-2012 YUCHENG HU
*
* ---------------------------------------------------------
* OSSEZ (中国) 信息技术有限公司
* http://www.ossez.com
* http://src.ossez.com
*
* CONTACT
* huyuchengus@gmail.com / yucheng.hu@ossez.com
*
* ---------------------------------------------------------
* [A] GNU GENERAL PUBLIC LICENSE GNU/LGPL
* [B] Apache License, Version 2.0
*
* ---------------------------------------------------------
* NOTE
* 1. 所有的语言配置文件必须采用无 BOM UTF-8 编码
* 2. 本语言文件为 ossez-5.4.0 分支,适用于 vTiger 5.4.0
* ---------------------------------------------------------
*/
$mod_strings = Array(
'ModuleName' => 'Module Name',
'SINGLE_ModuleName' => 'Module Name',
'ModuleName ID' => 'Module Name ID',
'LBL_CUSTOM_INFORMATION' => 'Custom Information',
'LBL_MODULEBLOCK_INFORMATION' => 'ModuleBlock Information',
'ModuleFieldLabel' => 'ModuleFieldLabel Text',
);
?>

View File

@ -0,0 +1,46 @@
<?php
/*+**********************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
************************************************************************************/
require_once('include/database/PearDatabase.php');
@include_once('user_privileges/default_module_view.php');
global $adb, $singlepane_view, $currentModule;
$idlist = vtlib_purify($_REQUEST['idlist']);
$destinationModule = vtlib_purify($_REQUEST['destination_module']);
$parenttab = getParentTab();
$forCRMRecord = vtlib_purify($_REQUEST['parentid']);
$mode = $_REQUEST['mode'];
if($singlepane_view == 'true')
$action = "DetailView";
else
$action = "CallRelatedList";
$focus = CRMEntity::getInstance($currentModule);
if($mode == 'delete') {
// Split the string of ids
$ids = explode (";",$idlist);
if(!empty($ids)) {
$focus->delete_related_module($currentModule, $forCRMRecord, $destinationModule, $ids);
}
} else {
if(!empty($_REQUEST['idlist'])) {
// Split the string of ids
$ids = explode (";",trim($idlist,";"));
} else if(!empty($_REQUEST['entityid'])){
$ids = $_REQUEST['entityid'];
}
if(!empty($ids)) {
$focus->save_related_module($currentModule, $forCRMRecord, $destinationModule, $ids);
}
}
header("Location: index.php?module=$currentModule&record=$forCRMRecord&action=$action&parenttab=$parenttab");
?>

View File

@ -0,0 +1,27 @@
Using skeleton module
=====================
1. Copy ModuleDir/<target_vtiger_version> to modules/<NewModuleName>
2. Rename modules/<NewModuleName>/ModuleFile.php to <NewModuleName>.php
3. Rename modules/<NewModuleName>/ModuleFileAjax.php to <NewModuleName>Ajax.php
4. Rename modules/<NewModuleName>/ModuleFile.js to <NewModuleName>.js
5. Edit <NewModuleName>.php
a. Update $table_name and $table_index (Module table name and table index column)
b. Update $groupTable
c. Update $tab_name, $tab_name_index
d. Update $list_fields, $list_fields_name, $sortby_fields
e. Update $detailview_links
f. Update $default_order_by, $default_sort_order
g. Update $customFieldTable
h. Rename class ModuleClass to class <NewModuleName>
Refer documentation for more details.

181
vtlib/Vtiger/Access.php Normal file
View File

@ -0,0 +1,181 @@
<?php
/*+***********************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
*************************************************************************************/
include_once('include/utils/UserInfoUtil.php');
include_once('vtlib/Vtiger/Utils.php');
include_once('vtlib/Vtiger/Profile.php');
/**
* Provides API to control Access like Sharing, Tools etc. for vtiger CRM Module
* @package vtlib
*/
class Vtiger_Access {
/**
* 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, $delim=true) {
Vtiger_Utils::Log($message, $delim);
}
/**
* Get unique id for sharing access record.
* @access private
*/
static function __getDefaultSharingAccessId() {
global $adb;
return $adb->getUniqueID('vtiger_def_org_share');
}
/**
* Recalculate sharing access rules.
* @internal This function could take up lot of resource while execution
* @access private
*/
static function syncSharingAccess() {
self::log("Recalculating sharing rules ... ", false);
RecalculateSharingRules();
self::log("DONE");
}
/**
* Enable or Disable sharing access control to module
* @param Vtiger_Module Instance of the module to use
* @param Boolean true to enable sharing access, false disable sharing access
* @access private
*/
static function allowSharing($moduleInstance, $enable=true) {
global $adb;
$ownedby = $enable? 0 : 1;
$adb->pquery("UPDATE vtiger_tab set ownedby=? WHERE tabid=?", Array($ownedby, $moduleInstance->id));
self::log(($enable? "Enabled" : "Disabled") . " sharing access control ... DONE");
}
/**
* Initialize sharing access.
* @param Vtiger_Module Instance of the module to use
* @access private
* @internal This method is called from Vtiger_Module during creation.
*/
static function initSharing($moduleInstance) {
global $adb;
$result = $adb->query("SELECT share_action_id from vtiger_org_share_action_mapping WHERE share_action_name in
('Public: Read Only', 'Public: Read, Create/Edit', 'Public: Read, Create/Edit, Delete', 'Private')");
for($index = 0; $index < $adb->num_rows($result); ++$index) {
$actionid = $adb->query_result($result, $index, 'share_action_id');
$adb->pquery("INSERT INTO vtiger_org_share_action2tab(share_action_id,tabid) VALUES(?,?)", Array($actionid, $moduleInstance->id));
}
self::log("Setting up sharing access options ... DONE");
}
/**
* Delete sharing access setup for module
* @param Vtiger_Module Instance of module to use
* @access private
* @internal This method is called from Vtiger_Module during deletion.
*/
static function deleteSharing($moduleInstance) {
global $adb;
$adb->pquery("DELETE FROM vtiger_org_share_action2tab WHERE tabid=?", Array($moduleInstance->id));
self::log("Deleting sharing access ... DONE");
}
/**
* Set default sharing for a module
* @param Vtiger_Module Instance of the module
* @param String Permission text should be one of ['Public_ReadWriteDelete', 'Public_ReadOnly', 'Public_ReadWrite', 'Private']
* @access private
*/
static function setDefaultSharing($moduleInstance, $permission_text='Public_ReadWriteDelete') {
global $adb;
$permission_text = strtolower($permission_text);
if($permission_text == 'public_readonly') $permission = 0;
else if($permission_text == 'public_readwrite') $permission = 1;
else if($permission_text == 'public_readwritedelete') $permission = 2;
else if($permission_text == 'private') $permission = 3;
else $permission = 2; // public_readwritedelete is default
$editstatus = 0; // 0 or 1
$result = $adb->pquery("SELECT * FROM vtiger_def_org_share WHERE tabid=?", Array($moduleInstance->id));
if($adb->num_rows($result)) {
$ruleid = $adb->query_result($result, 0, 'ruleid');
$adb->pquery("UPDATE vtiger_def_org_share SET permission=? WHERE ruleid=?", Array($permission, $ruleid));
} else {
$ruleid = self::__getDefaultSharingAccessId();
$adb->pquery("INSERT INTO vtiger_def_org_share (ruleid,tabid,permission,editstatus) VALUES(?,?,?,?)",
Array($ruleid,$moduleInstance->id,$permission,$editstatus));
}
self::syncSharingAccess();
}
/**
* Enable tool for module.
* @param Vtiger_Module Instance of module to use
* @param String Tool (action name) like Import, Export, Merge
* @param Boolean true to enable tool, false to disable
* @param Integer (optional) profile id to use, false applies to all profile.
* @access private
*/
static function updateTool($moduleInstance, $toolAction, $flag, $profileid=false) {
global $adb;
$result = $adb->pquery("SELECT actionid FROM vtiger_actionmapping WHERE actionname=?", Array($toolAction));
if($adb->num_rows($result)) {
$actionid = $adb->query_result($result, 0, 'actionid');
$permission = ($flag == true)? '0' : '1';
$profileids = Array();
if($profileid) {
$profileids[] = $profileid;
} else {
$profileids = Vtiger_Profile::getAllIds();
}
self::log( ($flag? 'Enabling':'Disabling') . " $toolAction for Profile [", false);
foreach($profileids as $useprofileid) {
$result = $adb->pquery("SELECT permission FROM vtiger_profile2utility WHERE profileid=? AND tabid=? AND activityid=?",
Array($useprofileid, $moduleInstance->id, $actionid));
if($adb->num_rows($result)) {
$curpermission = $adb->query_result($result, 0, 'permission');
if($curpermission != $permission) {
$adb->pquery("UPDATE vtiger_profile2utility set permission=? WHERE profileid=? AND tabid=? AND activityid=?",
Array($permission, $useprofileid, $moduleInstance->id, $actionid));
}
} else {
$adb->pquery("INSERT INTO vtiger_profile2utility (profileid, tabid, activityid, permission) VALUES(?,?,?,?)",
Array($useprofileid, $moduleInstance->id, $actionid, $permission));
}
self::log("$useprofileid,", false);
}
self::log("] ... DONE");
}
}
/**
* Delete tool (actions) of the module
* @param Vtiger_Module Instance of module to use
*/
static function deleteTools($moduleInstance) {
global $adb;
$adb->pquery("DELETE FROM vtiger_profile2utility WHERE tabid=?", Array($moduleInstance->id));
self::log("Deleting tools ... DONE");
}
}
?>

215
vtlib/Vtiger/Block.php Normal file
View File

@ -0,0 +1,215 @@
<?php
/*+*******************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
******************************************************************************/
include_once('vtlib/Vtiger/Utils.php');
/**
* Provides API to work with vtiger CRM Module Blocks
* @package vtlib
*/
class Vtiger_Block {
/** ID of this block instance */
var $id;
/** Label for this block instance */
var $label;
var $sequence;
var $showtitle = 0;
var $visible = 0;
var $increateview = 0;
var $ineditview = 0;
var $indetailview = 0;
var $module;
/**
* Constructor
*/
function __construct() {
}
/**
* Get unquie id for this instance
* @access private
*/
function __getUniqueId() {
global $adb;
/** Sequence table was added from 5.1.0 */
$maxblockid = $adb->getUniqueID('vtiger_blocks');
return $maxblockid;
}
/**
* Get next sequence value to use for this block instance
* @access private
*/
function __getNextSequence() {
global $adb;
$result = $adb->pquery("SELECT MAX(sequence) as max_sequence from vtiger_blocks where tabid = ?", Array($this->module->id));
$maxseq = 0;
if($adb->num_rows($result)) {
$maxseq = $adb->query_result($result, 0, 'max_sequence');
}
return ++$maxseq;
}
/**
* Initialize this block instance
* @param Array Map of column name and value
* @param Vtiger_Module Instance of module to which this block is associated
* @access private
*/
function initialize($valuemap, $moduleInstance=false) {
$this->id = $valuemap[blockid];
$this->label= $valuemap[blocklabel];
$this->module=$moduleInstance? $moduleInstance: Vtiger_Module::getInstance($valuemap[tabid]);
}
/**
* Create vtiger CRM block
* @access private
*/
function __create($moduleInstance) {
global $adb;
$this->module = $moduleInstance;
$this->id = $this->__getUniqueId();
if(!$this->sequence) $this->sequence = $this->__getNextSequence();
$adb->pquery("INSERT INTO vtiger_blocks(blockid,tabid,blocklabel,sequence,show_title,visible,create_view,edit_view,detail_view)
VALUES(?,?,?,?,?,?,?,?,?)", Array($this->id, $this->module->id, $this->label,$this->sequence,
$this->showtitle, $this->visible,$this->increateview, $this->ineditview, $this->indetailview));
self::log("Creating Block $this->label ... DONE");
self::log("Module language entry for $this->label ... CHECK");
}
/**
* Update vtiger CRM block
* @access private
* @internal TODO
*/
function __update() {
self::log("Updating Block $this->label ... DONE");
}
/**
* Delete this instance
* @access private
*/
function __delete() {
global $adb;
self::log("Deleting Block $this->label ... ", false);
$adb->pquery("DELETE FROM vtiger_blocks WHERE blockid=?", Array($this->id));
self::log("DONE");
}
/**
* Save this block instance
* @param Vtiger_Module Instance of the module to which this block is associated
*/
function save($moduleInstance=false) {
if($this->id) $this->__update();
else $this->__create($moduleInstance);
return $this->id;
}
/**
* Delete block instance
* @param Boolean True to delete associated fields, False to avoid it
*/
function delete($recursive=true) {
if($recursive) {
$fields = Vtiger_Field::getAllForBlock($this);
foreach($fields as $fieldInstance) $fieldInstance->delete($recursive);
}
$this->__delete();
}
/**
* Add field to this block
* @param Vtiger_Field Instance of field to add to this block.
* @return Reference to this block instance
*/
function addField($fieldInstance) {
$fieldInstance->save($this);
return $this;
}
/**
* 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, $delim=true) {
Vtiger_Utils::Log($message, $delim);
}
/**
* 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;
$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);
}
return $instance;
}
/**
* Get all block instances associated with the module
* @param Vtiger_Module Instance of the module
*/
static function getAllForModule($moduleInstance) {
global $adb;
$instances = false;
$query = "SELECT * FROM vtiger_blocks WHERE tabid=?";
$queryParams = Array($moduleInstance->id);
$result = $adb->pquery($query, $queryParams);
for($index = 0; $index < $adb->num_rows($result); ++$index) {
$instance = new self();
$instance->initialize($adb->fetch_array($result), $moduleInstance);
$instances[] = $instance;
}
return $instances;
}
/**
* Delete all blocks associated with module
* @param Vtiger_Module Instnace of module to use
* @param Boolean true to delete associated fields, false otherwise
* @access private
*/
static function deleteForModule($moduleInstance, $recursive=true) {
global $adb;
if($recursive) Vtiger_Field::deleteForModule($moduleInstance);
$adb->pquery("DELETE FROM vtiger_blocks WHERE tabid=?", Array($moduleInstance->id));
self::log("Deleting blocks for module ... DONE");
}
}
?>

386
vtlib/Vtiger/Cron.php Normal file
View File

@ -0,0 +1,386 @@
<?php
/*+**********************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
*********************************************************************************** */
include_once 'vtlib/Vtiger/Utils.php';
require_once('include/database/PearDatabase.php');
/**
* Provides API to work with Cron tasks
* @package vtlib
*/
class Vtiger_Cron {
protected static $schemaInitialized = false;
protected static $instanceCache = array();
static $STATUS_DISABLED = 0;
static $STATUS_ENABLED = 1;
static $STATUS_RUNNING = 2;
protected $data;
protected $bulkMode = false;
/**
* Constructor
*/
protected function __construct($values) {
$this->data = $values;
self::$instanceCache[$this->getName()] = $this;
}
/**
* Get id reference of this instance.
*/
function getId() {
return $this->data['id'];
}
/**
* Get name of this task instance.
*/
function getName() {
return decode_html($this->data['name']);
}
/**
* Get the frequency set.
*/
function getFrequency() {
return intval($this->data['frequency']);
}
/**
* Get the status
*/
function getStatus() {
return intval($this->data['status']);
}
/**
* Get the timestamp lastrun started.
*/
function getLastStart() {
return intval($this->data['laststart']);
}
/**
* Get the timestamp lastrun ended.
*/
function getLastEnd() {
return intval($this->data['lastend']);
}
/**
* Get the user datetimefeild
*/
function getLastEndDateTime() {
if($this->data['lastend'] != NULL){
$lastEndDateTime = new DateTimeField(date('Y-m-d H:i:s', $this->data['lastend']));
return $lastEndDateTime->getDisplayDateTimeValue();
} else {
return '';
}
}
/**
*
* get the last start datetime field
*/
function getLastStartDateTime() {
if($this->data['laststart'] != NULL){
$lastStartDateTime = new DateTimeField(date('Y-m-d H:i:s', $this->data['laststart']));
return $lastStartDateTime->getDisplayDateTimeValue();
} else {
return '';
}
}
/**
* Get Time taken to complete task
*/
function getTimeDiff() {
$lastStart = $this->getLastStart();
$lastEnd = $this->getLastEnd();
$timeDiff = $lastEnd - $lastStart;
return $timeDiff;
}
/**
* Get the configured handler file.
*/
function getHandlerFile() {
return $this->data['handler_file'];
}
/**
*Get the Module name
*/
function getModule() {
return $this->data['module'];
}
/**
* get the Sequence
*/
function getSequence() {
return $this->data['sequence'];
}
/**
* get the description of cron
*/
function getDescription(){
return $this->data['description'];
}
/**
* Check if task is right state for running.
*/
function isRunnable() {
$runnable = false;
if (!$this->isDisabled()) {
// Take care of last time (end - on success, start - if timedout)
$lastTime = ($this->getLastEnd() > 0) ? $this->getLastEnd() : $this->getLastStart();
$elapsedTime = time() - $lastTime;
$runnable = ($elapsedTime >= $this->getFrequency());
}
return $runnable;
}
/**
* Helper function to check the status value.
*/
function statusEqual($value) {
$status = intval($this->data['status']);
return $status == $value;
}
/**
* Is task in running status?
*/
function isRunning() {
return $this->statusEqual(self::$STATUS_RUNNING);
}
/**
* Is task enabled?
*/
function isEnabled() {
return $this->statusEqual(self::$STATUS_ENABLED);
}
/**
* Is task disabled?
*/
function isDisabled() {
return $this->statusEqual(self::$STATUS_DISABLED);
}
/**
* Update status
*/
function updateStatus($status) {
switch (intval($status)) {
case self::$STATUS_DISABLED:
case self::$STATUS_ENABLED:
case self::$STATUS_RUNNING:
break;
default:
throw new Exception('Invalid status');
}
self::querySilent('UPDATE vtiger_cron_task SET status=? WHERE id=?', array($status, $this->getId()));
}
/*
* update frequency
*/
function updateFrequency($frequency) {
self::querySilent('UPDATE vtiger_cron_task SET frequency=? WHERE id=?', array($frequency, $this->getId()));
}
/**
* Mark this instance as running.
*/
function markRunning() {
self::querySilent('UPDATE vtiger_cron_task SET status=?, laststart=?, lastend=? WHERE id=?', array(self::$STATUS_RUNNING, time(), 0, $this->getId()));
return $this;
}
/**
* Mark this instance as finished.
*/
function markFinished() {
self::querySilent('UPDATE vtiger_cron_task SET status=?, lastend=? WHERE id=?', array(self::$STATUS_ENABLED, time(), $this->getId()));
return $this;
}
/**
* Set the bulkMode flag
*/
function setBulkMode($mode = null) {
$this->bulkMode = $mode;
}
/**
* Is task in bulk mode execution?
*/
function inBulkMode() {
return $this->bulkMode;
}
/**
* Detect if the task was started by never finished.
*/
function hadTimedout() {
if($this->data['lastend'] === 0 && $this->data['laststart'] != 0)
return intval($this->data['lastend']);
}
/**
* Execute SQL query silently (even when table doesn't exist)
*/
protected static function querySilent($sql, $params=false) {
global $adb;
$old_dieOnError = $adb->dieOnError;
$adb->dieOnError = false;
$result = $adb->pquery($sql, $params);
$adb->dieOnError = $old_dieOnError;
return $result;
}
/**
* 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 long, lastend long, status int,module VARCHAR(100),
sequence int,description TEXT )',true);
}
self::$schemaInitialized = true;
}
}
static function nextSequence() {
global $adb;
$result = self::querySilent('SELECT MAX(sequence) FROM vtiger_cron_task ORDER BY SEQUENCE');
if ($result && $adb->num_rows($result)) {
$row = $adb->fetch_array($result);
}
if($row == NULL) {
$row['max(sequence)'] = 1;
}
return $row['max(sequence)']+1;
}
/**
* Register cron task.
*/
static function register($name, $handler_file, $frequency, $module = 'Home', $status = 1, $sequence = 0, $description = '') {
self::initializeSchema();
global $adb;
$instance = self::getInstance($name);
if($sequence == 0) {
$sequence = self::nextSequence();
}
self::querySilent('INSERT INTO vtiger_cron_task (name, handler_file, frequency, status, sequence,module,description) VALUES(?,?,?,?,?,?,?)',
array($name, $handler_file, $frequency, $status, $sequence, $module,$description));
}
/**
* De-register cron task.
*/
static function deregister($name) {
self::querySilent('DELETE FROM vtiger_cron_task WHERE name=?', array($name));
if (isset(self::$instanceCache["$name"])) {
unset(self::$instanceCache["$name"]);
}
}
/**
* Get instances that are active (not disabled)
*/
static function listAllActiveInstances($byStatus = 0) {
global $adb;
$instances = array();
if($byStatus == 0) {
$result = self::querySilent('SELECT * FROM vtiger_cron_task WHERE status <> ? ORDER BY SEQUENCE',array(self::$STATUS_DISABLED ));
}
else {
$result = self::querySilent('SELECT * FROM vtiger_cron_task ORDER BY SEQUENCE');
}
if ($result && $adb->num_rows($result)) {
while ($row = $adb->fetch_array($result)) {
$instances[] = new Vtiger_Cron($row);
}
}
return $instances;
}
/**
* Get instance of cron task.
*/
static function getInstance($name) {
global $adb;
$instance = false;
if (isset(self::$instanceCache["$name"])) {
$instance = self::$instanceCache["$name"];
}
if ($instance === false) {
$result = self::querySilent('SELECT * FROM vtiger_cron_task WHERE name=?', array($name));
if ($result && $adb->num_rows($result)) {
$instance = new Vtiger_Cron($adb->fetch_array($result));
}
}
return $instance;
}
/**
* Get instance of cron job by id
*/
static function getInstanceById($id) {
global $adb;
$instance = false;
if (isset(self::$instanceCache[$id])) {
$instance = self::$instanceCache[$id];
}
if ($instance === false) {
$result = self::querySilent('SELECT * FROM vtiger_cron_task WHERE id=?', array($id));
if ($result && $adb->num_rows($result)) {
$instance = new Vtiger_Cron($adb->fetch_array($result));
}
}
return $instance;
}
static function listAllInstancesByModule($module) {
global $adb;
$instances = array();
$result = self::querySilent('SELECT * FROM vtiger_cron_task WHERE module=?',array($module));
if ($result && $adb->num_rows($result)) {
while ($row = $adb->fetch_array($result)) {
$instances[] = new Vtiger_Cron($row);
}
}
return $instances;
}
}
?>

127
vtlib/Vtiger/Event.php Normal file
View File

@ -0,0 +1,127 @@
<?php
/*+**********************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
************************************************************************************/
include_once('vtlib/Vtiger/Utils.php');
include_once('modules/Users/Users.php');
@include_once('include/events/include.inc');
/**
* Provides API to work with vtiger CRM Eventing (available from vtiger 5.1)
* @package vtlib
*/
class Vtiger_Event {
/** Event name like: vtiger.entity.aftersave, vtiger.entity.beforesave */
var $eventname;
/** Event handler class to use */
var $classname;
/** Filename where class is defined */
var $filename;
/** Condition for the event */
var $condition;
/** Internal caching */
static $is_supported = '';
/**
* 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, $delim=true) {
Vtiger_Utils::Log($message, $delim);
}
/**
* Check if vtiger CRM support Events
*/
static function hasSupport() {
if(self::$is_supported === '') {
self::$is_supported = Vtiger_Utils::checkTable('vtiger_eventhandlers');
}
return self::$is_supported;
}
/**
* 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='') {
// Security check on fileaccess, don't die if it fails
if(Vtiger_Utils::checkFileAccess($filename, false)) {
global $adb;
$eventsManager = new VTEventsManager($adb);
$eventsManager->registerHandler($eventname, $filename, $classname, $condition);
$eventsManager->setModuleForHandler($moduleInstance->name, $classname);
self::log("Registering Event $eventname with [$filename] $classname ... DONE");
}
}
/**
* Trigger event based on CRM Record
* @param String Name of the Event to trigger
* @param Integer CRM record id on which event needs to be triggered.
*/
static function trigger($eventname, $crmid) {
if(!self::hasSupport()) return;
global $adb;
$checkres = $adb->pquery("SELECT setype, crmid, deleted FROM vtiger_crmentity WHERE crmid=?", Array($crmid));
if($adb->num_rows($checkres)) {
$result = $adb->fetch_array($checkres, 0);
if($result['deleted'] == '0') {
$module = $result['setype'];
$moduleInstance = CRMEntity::getInstance($module);
$moduleInstance->retrieve_entity_info($result['crmid'], $module);
$moduleInstance->id = $result['crmid'];
global $current_user;
if(!$current_user) {
$current_user = new Users();
$current_user->id = $moduleInstance->column_fields['assigned_user_id'];
}
// Trigger the event
$em = new VTEventsManager($adb);
$em->triggerEvent($eventname, VTEntityData::fromCRMEntity($moduleInstance));
}
}
}
/**
* Get all the registered module events
* @param Vtiger_Module Instance of the module to use
*/
static function getAll($moduleInstance) {
global $adb;
$events = false;
if(self::hasSupport()) {
// Get all events related to module
$records = $adb->pquery("SELECT * FROM vtiger_eventhandlers WHERE handler_class IN
(SELECT handler_class FROM vtiger_eventhandler_module WHERE module_name=?)", Array($moduleInstance->name));
if($records) {
while($record = $adb->fetch_array($records)) {
$event = new Vtiger_Event();
$event->eventname = $record['event_name'];
$event->classname = $record['handler_class'];
$event->filename = $record['handler_path'];
$event->condition = $record['condition'];
$events[] = $event;
}
}
}
return $events;
}
}
?>

View File

@ -0,0 +1,44 @@
<?php
/*+***********************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
*************************************************************************************/
require_once('vtlib/thirdparty/parser/feed/simplepie.inc');
/**
* Extends SimplePie (feed parser library for Rss, Atom, etc)
* @package vtlib
*/
class Vtiger_Feed_Parser extends SimplePie {
var $vt_cachelocation = 'test/vtlib/feedcache';
var $vt_fetchdone = false;
/**
* Parse the feed url.
* @param String Feed url (RSS, ATOM etc)
* @param Integer Timeout value (to try connecting to url)
*/
function vt_dofetch($url, $timeout=10) {
$this->set_timeout($timeout);
$this->set_feed_url($url);
$this->enable_order_by_date(false);
$this->enable_cache(false);
$this->init();
$this->vt_fetchdone = true;
}
/**
* Parse the content as feed.
* @param String Feed content
*/
function vt_doparse($content) {
$this->set_raw_data($content);
$this->init();
$this->vt_fetchdone = true;
}
}
?>

262
vtlib/Vtiger/Field.php Normal file
View File

@ -0,0 +1,262 @@
<?php
/*+**********************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
************************************************************************************/
include_once('vtlib/Vtiger/Utils.php');
include_once('vtlib/Vtiger/FieldBasic.php');
/**
* Provides APIs to control vtiger CRM Field
* @package vtlib
*/
class Vtiger_Field extends Vtiger_FieldBasic {
/**
* Get unique picklist id to use
* @access private
*/
function __getPicklistUniqueId() {
global $adb;
return $adb->getUniqueID('vtiger_picklist');
}
/**
* Set values for picklist field (for all the roles)
* @param Array List of values to add.
*
* @internal Creates picklist base if it does not exists
*/
function setPicklistValues($values) {
global $adb,$default_charset;
// Non-Role based picklist values
if($this->uitype == '16') {
$this->setNoRolePicklistValues($values);
return;
}
$picklist_table = 'vtiger_'.$this->name;
$picklist_idcol = $this->name.'id';
if(!Vtiger_Utils::CheckTable($picklist_table)) {
Vtiger_Utils::CreateTable(
$picklist_table,
"($picklist_idcol INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
$this->name VARCHAR(200) NOT NULL,
presence INT (1) NOT NULL DEFAULT 1,
picklist_valueid INT NOT NULL DEFAULT 0)",
true);
$new_picklistid = $this->__getPicklistUniqueId();
$adb->pquery("INSERT INTO vtiger_picklist (picklistid,name) VALUES(?,?)",Array($new_picklistid, $this->name));
self::log("Creating table $picklist_table ... DONE");
} else {
$new_picklistid = $adb->query_result(
$adb->pquery("SELECT picklistid FROM vtiger_picklist WHERE name=?", Array($this->name)), 0, 'picklistid');
}
$specialNameSpacedPicklists = array(
'opportunity_type'=>'opptypeid',
'duration_minutes'=>'minutesid',
'recurringtype'=>'recurringeventid'
);
// Fix Table ID column names
$fieldName = (string)$this->name;
if(in_array($fieldName.'_id', $adb->getColumnNames($picklist_table))) {
$picklist_idcol = $fieldName.'_id';
} elseif(array_key_exists($fieldName, $specialNameSpacedPicklists)) {
$picklist_idcol = $specialNameSpacedPicklists[$fieldName];
}
// END
// Add value to picklist now
$sortid = 0; // TODO To be set per role
foreach($values as $value) {
$value = htmlentities($value,ENT_QUOTES,$default_charset);
$new_picklistvalueid = getUniquePicklistID();
$presence = 1; // 0 - readonly, Refer function in include/ComboUtil.php
$new_id = $adb->getUniqueID($picklist_table);
$adb->pquery("INSERT INTO $picklist_table($picklist_idcol, $this->name, presence, picklist_valueid) VALUES(?,?,?,?)",
Array($new_id, $value, $presence, $new_picklistvalueid));
++$sortid;
// Associate picklist values to all the role
$adb->query("INSERT INTO vtiger_role2picklist(roleid, picklistvalueid, picklistid, sortid) SELECT roleid,
$new_picklistvalueid, $new_picklistid, $sortid FROM vtiger_role");
}
}
/**
* Set values for picklist field (non-role based)
* @param Array List of values to add
*
* @internal Creates picklist base if it does not exists
* @access private
*/
function setNoRolePicklistValues($values) {
global $adb;
$picklist_table = 'vtiger_'.$this->name;
$picklist_idcol = $this->name.'id';
if(!Vtiger_Utils::CheckTable($picklist_table)) {
Vtiger_Utils::CreateTable(
$picklist_table,
"($picklist_idcol INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
$this->name VARCHAR(200) NOT NULL,
sortorderid INT(11),
presence INT (11) NOT NULL DEFAULT 1)",
true);
self::log("Creating table $picklist_table ... DONE");
}
// Add value to picklist now
$sortid = 1;
foreach($values as $value) {
$presence = 1; // 0 - readonly, Refer function in include/ComboUtil.php
$new_id = $adb->getUniqueId($picklist_table);
$adb->pquery("INSERT INTO $picklist_table($picklist_idcol, $this->name, sortorderid, presence) VALUES(?,?,?,?)",
Array($new_id, $value, $sortid, $presence));
$sortid = $sortid+1;
}
}
/**
* Set relation between field and modules (UIType 10)
* @param Array List of module names
*
* @internal Creates table vtiger_fieldmodulerel if it does not exists
*/
function setRelatedModules($moduleNames) {
// We need to create core table to capture the relation between the field and modules.
if(!Vtiger_Utils::CheckTable('vtiger_fieldmodulerel')) {
Vtiger_Utils::CreateTable(
'vtiger_fieldmodulerel',
'(fieldid INT NOT NULL, module VARCHAR(100) NOT NULL, relmodule VARCHAR(100) NOT NULL, status VARCHAR(10), sequence INT)',
true
);
}
// END
global $adb;
foreach($moduleNames as $relmodule) {
$checkres = $adb->pquery('SELECT * FROM vtiger_fieldmodulerel WHERE fieldid=? AND module=? AND relmodule=?',
Array($this->id, $this->getModuleName(), $relmodule));
// If relation already exist continue
if($adb->num_rows($checkres)) continue;
$adb->pquery('INSERT INTO vtiger_fieldmodulerel(fieldid, module, relmodule) VALUES(?,?,?)',
Array($this->id, $this->getModuleName(), $relmodule));
self::log("Setting $this->name relation with $relmodule ... DONE");
}
return true;
}
/**
* 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;
}
/**
* Get Vtiger_Field instance by fieldid or fieldname
* @param mixed fieldid or fieldname
* @param Vtiger_Module Instance of the module if fieldname 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_field WHERE fieldid=?";
$queryParams = Array($value);
} else {
$query = "SELECT * FROM vtiger_field WHERE fieldname=? 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);
}
return $instance;
}
/**
* Get Vtiger_Field instances related to block
* @param Vtiger_Block Instnace of block to use
* @param Vtiger_Module Instance of module to which block is associated
*/
static function getAllForBlock($blockInstance, $moduleInstance=false) {
global $adb;
$instances = false;
$query = false;
$queryParams = false;
if($moduleInstance) {
$query = "SELECT * FROM vtiger_field WHERE block=? AND tabid=?";
$queryParams = Array($blockInstance->id, $moduleInstance->id);
} else {
$query = "SELECT * FROM vtiger_field WHERE block=?";
$queryParams = Array($blockInstance->id);
}
$result = $adb->pquery($query, $queryParams);
for($index = 0; $index < $adb->num_rows($result); ++$index) {
$instance = new self();
$instance->initialize($adb->fetch_array($result), $moduleInstance, $blockInstance);
$instances[] = $instance;
}
return $instances;
}
/**
* Get Vtiger_Field instances related to module
* @param Vtiger_Module Instance of module to use
*/
static function getAllForModule($moduleInstance) {
global $adb;
$instances = false;
$query = "SELECT * FROM vtiger_field WHERE tabid=?";
$queryParams = Array($moduleInstance->id);
$result = $adb->pquery($query, $queryParams);
for($index = 0; $index < $adb->num_rows($result); ++$index) {
$instance = new self();
$instance->initialize($adb->fetch_array($result), $moduleInstance);
$instances[] = $instance;
}
return $instances;
}
/**
* Delete fields associated with the module
* @param Vtiger_Module Instance of module
* @access private
*/
static function deleteForModule($moduleInstance) {
global $adb;
$adb->pquery("DELETE FROM vtiger_field WHERE tabid=?", Array($moduleInstance->id));
self::log("Deleting fields of the module ... DONE");
}
}
?>

283
vtlib/Vtiger/FieldBasic.php Normal file
View File

@ -0,0 +1,283 @@
<?php
/*+**********************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
************************************************************************************/
/**
* Provides basic API to work with vtiger CRM Fields
* @package vtlib
*/
class Vtiger_FieldBasic {
/** ID of this field instance */
var $id;
var $name;
var $label = false;
var $table = false;
var $column = false;
var $columntype = false;
var $helpinfo = '';
var $masseditable = 1; // Default: Enable massedit for field
var $uitype = 1;
var $typeofdata = 'V~O';
var $displaytype = 1;
var $generatedtype = 1;
var $readonly = 1;
var $presence = 2;
var $defaultvalue = '';
var $maximumlength = 100;
var $sequence = false;
var $quickcreate = 1;
var $quicksequence = false;
var $info_type = 'BAS';
var $block;
/**
* Constructor
*/
function __construct() {
}
/**
* Initialize this instance
* @param Array
* @param Vtiger_Module Instance of module to which this field belongs
* @param Vtiger_Block Instance of block to which this field belongs
* @access private
*/
function initialize($valuemap, $moduleInstance=false, $blockInstance=false) {
$this->id = $valuemap['fieldid'];
$this->name = $valuemap['fieldname'];
$this->label= $valuemap['fieldlabel'];
$this->column = $valuemap['columnname'];
$this->table = $valuemap['tablename'];
$this->uitype = $valuemap['uitype'];
$this->typeofdata = $valuemap['typeofdata'];
$this->helpinfo = $valuemap['helpinfo'];
$this->masseditable = $valuemap['masseditable'];
$this->block= $blockInstance? $blockInstance : Vtiger_Block::getInstance($valuemap['block'], $moduleInstance);
}
/** Cache (Record) the schema changes to improve performance */
static $__cacheSchemaChanges = Array();
/**
* Initialize vtiger schema changes.
* @access private
*/
function __handleVtigerCoreSchemaChanges() {
// Add helpinfo column to the vtiger_field table
if(empty(self::$__cacheSchemaChanges['vtiger_field.helpinfo'])) {
Vtiger_Utils::AddColumn('vtiger_field', 'helpinfo', ' TEXT');
self::$__cacheSchemaChanges['vtiger_field.helpinfo'] = true;
}
}
/**
* Get unique id for this instance
* @access private
*/
function __getUniqueId() {
global $adb;
return $adb->getUniqueID('vtiger_field');
}
/**
* Get next sequence id to use within a block for this instance
* @access private
*/
function __getNextSequence() {
global $adb;
$result = $adb->pquery("SELECT MAX(sequence) AS max_seq FROM vtiger_field WHERE tabid=? AND block=?",
Array($this->getModuleId(), $this->getBlockId()));
$maxseq = 0;
if($result && $adb->num_rows($result)) {
$maxseq = $adb->query_result($result, 0, 'max_seq');
$maxseq += 1;
}
return $maxseq;
}
/**
* Get next quick create sequence id for this instance
* @access private
*/
function __getNextQuickCreateSequence() {
global $adb;
$result = $adb->pquery("SELECT MAX(quickcreatesequence) AS max_quickcreateseq FROM vtiger_field WHERE tabid=?",
Array($this->getModuleId()));
$max_quickcreateseq = 0;
if($result && $adb->num_rows($result)) {
$max_quickcreateseq = $adb->query_result($result, 0, 'max_quickcreateseq');
$max_quickcreateseq += 1;
}
return $max_quickcreateseq;
}
/**
* Create this field instance
* @param Vtiger_Block Instance of the block to use
* @access private
*/
function __create($blockInstance) {
$this->__handleVtigerCoreSchemaChanges();
global $adb;
$this->block = $blockInstance;
$moduleInstance = $this->getModuleInstance();
$this->id = $this->__getUniqueId();
if(!$this->sequence) {
$this->sequence = $this->__getNextSequence();
}
if($this->quickcreate != 1) { // If enabled for display
if(!$this->quicksequence) {
$this->quicksequence = $this->__getNextQuickCreateSequence();
}
} else {
$this->quicksequence = null;
}
// Initialize other variables which are not done
if(!$this->table) $this->table = $moduleInstance->basetable;
if(!$this->column) {
$this->column = strtolower($this->name);
if(!$this->columntype) $this->columntype = 'VARCHAR(100)';
}
if(!$this->label) $this->label = $this->name;
$adb->pquery("INSERT INTO vtiger_field (tabid, fieldid, columnname, tablename, generatedtype,
uitype, fieldname, fieldlabel, readonly, presence, defaultvalue, maximumlength, sequence,
block, displaytype, typeofdata, quickcreate, quickcreatesequence, info_type, helpinfo)
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",
Array($this->getModuleId(), $this->id, $this->column, $this->table, $this->generatedtype,
$this->uitype, $this->name, $this->label, $this->readonly, $this->presence, $this->defaultvalue,
$this->maximumlength, $this->sequence, $this->getBlockId(), $this->displaytype, $this->typeofdata,
$this->quickcreate, $this->quicksequence, $this->info_type, $this->helpinfo));
// Set the field status for mass-edit (if set)
$adb->pquery('UPDATE vtiger_field SET masseditable=? WHERE fieldid=?', Array($this->masseditable, $this->id));
Vtiger_Profile::initForField($this);
if(!empty($this->columntype)) {
Vtiger_Utils::AddColumn($this->table, $this->column, $this->columntype);
}
self::log("Creating Field $this->name ... DONE");
self::log("Module language mapping for $this->label ... CHECK");
}
/**
* Update this field instance
* @access private
* @internal TODO
*/
function __update() {
self::log("Updating Field $this->name ... DONE");
}
/**
* Delete this field instance
* @access private
*/
function __delete() {
global $adb;
Vtiger_Profile::deleteForField($this);
$adb->pquery("DELETE FROM vtiger_field WHERE fieldid=?", Array($this->id));
self::log("Deleteing Field $this->name ... DONE");
}
/**
* Get block id to which this field instance is associated
*/
function getBlockId() {
return $this->block->id;
}
/**
* Get module id to which this field instance is associated
*/
function getModuleId() {
return $this->block->module->id;
}
/**
* Get module name to which this field instance is associated
*/
function getModuleName() {
return $this->block->module->name;
}
/**
* Get module instance to which this field instance is associated
*/
function getModuleInstance(){
return $this->block->module;
}
/**
* Save this field instance
* @param Vtiger_Block Instance of block to which this field should be added.
*/
function save($blockInstance=false) {
if($this->id) $this->__update();
else $this->__create($blockInstance);
return $this->id;
}
/**
* Delete this field instance
*/
function delete() {
$this->__delete();
}
/**
* Set Help Information for this instance.
* @param String Help text (content)
*/
function setHelpInfo($helptext) {
// Make sure to initialize the core tables first
$this->__handleVtigerCoreSchemaChanges();
global $adb;
$adb->pquery('UPDATE vtiger_field SET helpinfo=? WHERE fieldid=?', Array($helptext, $this->id));
self::log("Updated help information of $this->name ... DONE");
}
/**
* Set Masseditable information for this instance.
* @param Integer Masseditable value
*/
function setMassEditable($value) {
global $adb;
$adb->pquery('UPDATE vtiger_field SET masseditable=? WHERE fieldid=?', Array($value, $this->id));
self::log("Updated masseditable information of $this->name ... DONE");
}
/**
* 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, $delim=true) {
Vtiger_Utils::Log($message, $delim);
}
}
?>

291
vtlib/Vtiger/Filter.php Normal file
View File

@ -0,0 +1,291 @@
<?php
/*+**********************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
************************************************************************************/
include_once('vtlib/Vtiger/Utils.php');
include_once('vtlib/Vtiger/Version.php');
/**
* Provides API to work with vtiger CRM Custom View (Filter)
* @package vtlib
*/
class Vtiger_Filter {
/** ID of this filter instance */
var $id;
var $name;
var $isdefault;
var $status = false; // 5.1.0 onwards
var $inmetrics = false;
var $entitytype= false;
var $module;
/**
* Constructor
*/
function __construct() {
}
/**
* Get unique id for this instance
* @access private
*/
function __getUniqueId() {
global $adb;
return $adb->getUniqueID('vtiger_customview');
}
/**
* Initialize this filter instance
* @param Vtiger_Module Instance of the module to which this filter is associated.
* @access private
*/
function initialize($valuemap, $moduleInstance=false) {
$this->id = $valuemap[cvid];
$this->name= $valuemap[viewname];
$this->module=$moduleInstance? $moduleInstance: Vtiger_Module::getInstance($valuemap[tabid]);
}
/**
* Create this instance
* @param Vtiger_Module Instance of the module to which this filter should be associated with
* @access private
*/
function __create($moduleInstance) {
global $adb;
$this->module = $moduleInstance;
$this->id = $this->__getUniqueId();
$this->isdefault = ($this->isdefault===true||$this->isdefault=='true')?1:0;
$this->inmetrics = ($this->inmetrics===true||$this->inmetrics=='true')?1:0;
$adb->pquery("INSERT INTO vtiger_customview(cvid,viewname,setdefault,setmetrics,entitytype) VALUES(?,?,?,?,?)",
Array($this->id, $this->name, $this->isdefault, $this->inmetrics, $this->module->name));
self::log("Creating Filter $this->name ... DONE");
// Filters are role based from 5.1.0 onwards
if(!$this->status) {
if(strtoupper(trim($this->name)) == 'ALL') $this->status = '0'; // Default
else $this->status = '3'; // Public
$adb->pquery("UPDATE vtiger_customview SET status=? WHERE cvid=?", Array($this->status, $this->id));
self::log("Setting Filter $this->name to status [$this->status] ... DONE");
}
// END
}
/**
* Update this instance
* @access private
* @internal TODO
*/
function __update() {
self::log("Updating Filter $this->name ... DONE");
}
/**
* Delete this instance
* @access private
*/
function __delete() {
global $adb;
$adb->pquery("DELETE FROM vtiger_cvadvfilter WHERE cvid=?", Array($this->id));
$adb->pquery("DELETE FROM vtiger_cvcolumnlist WHERE cvid=?", Array($this->id));
$adb->pquery("DELETE FROM vtiger_customview WHERE cvid=?", Array($this->id));
}
/**
* Save this instance
* @param Vtiger_Module Instance of the module to use
*/
function save($moduleInstance=false) {
if($this->id) $this->__update();
else $this->__create($moduleInstance);
return $this->id;
}
/**
* Delete this instance
* @access private
*/
function delete() {
$this->__delete();
}
/**
* Get the column value to use in custom view tables.
* @param Vtiger_Field Instance of the field
* @access private
*/
function __getColumnValue($fieldInstance) {
$tod = split('~', $fieldInstance->typeofdata);
$displayinfo = $fieldInstance->getModuleName().'_'.str_replace(' ','_',$fieldInstance->label).':'.$tod[0];
$cvcolvalue = "$fieldInstance->table:$fieldInstance->column:$fieldInstance->name:$displayinfo";
return $cvcolvalue;
}
/**
* Add the field to this filer instance
* @param Vtiger_Field Instance of the field
* @param Integer Index count to use
*/
function addField($fieldInstance, $index=0) {
global $adb;
$cvcolvalue = $this->__getColumnValue($fieldInstance);
$adb->pquery("UPDATE vtiger_cvcolumnlist SET columnindex=columnindex+1 WHERE cvid=? AND columnindex>=? ORDER BY columnindex DESC",
Array($this->id, $index));
$adb->pquery("INSERT INTO vtiger_cvcolumnlist(cvid,columnindex,columnname) VALUES(?,?,?)", Array($this->id, $index, $cvcolvalue));
$this->log("Adding $fieldInstance->name to $this->name filter ... DONE");
return $this;
}
/**
* Add rule to this filter instance
* @param Vtiger_Field Instance of the field
* @param String One of [EQUALS, NOT_EQUALS, STARTS_WITH, ENDS_WITH, CONTAINS, DOES_NOT_CONTAINS, LESS_THAN,
* GREATER_THAN, LESS_OR_EQUAL, GREATER_OR_EQUAL]
* @param String Value to use for comparision
* @param Integer Index count to use
*/
function addRule($fieldInstance, $comparator, $comparevalue, $index=0) {
global $adb;
if(empty($comparator)) return $this;
$comparator = self::translateComparator($comparator);
$cvcolvalue = $this->__getColumnValue($fieldInstance);
$adb->pquery("UPDATE vtiger_cvadvfilter set columnindex=columnindex+1 WHERE cvid=? AND columnindex>=? ORDER BY columnindex DESC",
Array($this->id, $index));
$adb->pquery("INSERT INTO vtiger_cvadvfilter(cvid, columnindex, columnname, comparator, value) VALUES(?,?,?,?,?)",
Array($this->id, $index, $cvcolvalue, $comparator, $comparevalue));
Vtiger_Utils::Log("Adding Condition " . self::translateComparator($comparator,true) ." on $fieldInstance->name of $this->name filter ... DONE");
return $this;
}
/**
* Translate comparator (condition) to long or short form.
* @access private
* @internal Used from Vtiger_PackageExport also
*/
static function translateComparator($value, $tolongform=false) {
$comparator = false;
if($tolongform) {
$comparator = strtolower($value);
if($comparator == 'e') $comparator = 'EQUALS';
else if($comparator == 'n') $comparator = 'NOT_EQUALS';
else if($comparator == 's') $comparator = 'STARTS_WITH';
else if($comparator == 'ew') $comparator = 'ENDS_WITH';
else if($comparator == 'c') $comparator = 'CONTAINS';
else if($comparator == 'k') $comparator = 'DOES_NOT_CONTAINS';
else if($comparator == 'l') $comparator = 'LESS_THAN';
else if($comparator == 'g') $comparator = 'GREATER_THAN';
else if($comparator == 'm') $comparator = 'LESS_OR_EQUAL';
else if($comparator == 'h') $comparator = 'GREATER_OR_EQUAL';
} else {
$comparator = strtoupper($value);
if($comparator == 'EQUALS') $comparator = 'e';
else if($comparator == 'NOT_EQUALS') $comparator = 'n';
else if($comparator == 'STARTS_WITH') $comparator = 's';
else if($comparator == 'ENDS_WITH') $comparator = 'ew';
else if($comparator == 'CONTAINS') $comparator = 'c';
else if($comparator == 'DOES_NOT_CONTAINS') $comparator = 'k';
else if($comparator == 'LESS_THAN') $comparator = 'l';
else if($comparator == 'GREATER_THAN') $comparator = 'g';
else if($comparator == 'LESS_OR_EQUAL') $comparator = 'm';
else if($comparator == 'GREATER_OR_EQUAL') $comparator = 'h';
}
return $comparator;
}
/**
* 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, $delim=true) {
Vtiger_Utils::Log($message, $delim);
}
/**
* 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;
}
/**
* Get all instances of filter for the module
* @param Vtiger_Module Instance of module
*/
static function getAllForModule($moduleInstance) {
global $adb;
$instances = false;
$query = "SELECT * FROM vtiger_customview WHERE entitytype=?";
$queryParams = Array($moduleInstance->name);
$result = $adb->pquery($query, $queryParams);
for($index = 0; $index < $adb->num_rows($result); ++$index) {
$instance = new self();
$instance->initialize($adb->fetch_array($result), $moduleInstance);
$instances[] = $instance;
}
return $instances;
}
/**
* Delete filter associated for module
* @param Vtiger_Module Instance of module
*/
static function deleteForModule($moduleInstance) {
global $adb;
$cvidres = $adb->pquery("SELECT cvid FROM vtiger_customview WHERE entitytype=?", Array($moduleInstance->name));
if($adb->num_rows($cvidres)) {
$cvids = Array();
for($index = 0; $index < $adb->num_rows($cvidres); ++$index) {
$cvids[] = $adb->query_result($cvidres, $index, 'cvid');
}
if(!empty($cvids)) {
$adb->query("DELETE FROM vtiger_cvadvfilter WHERE cvid IN (" . implode(',', $cvids) . ")");
$adb->query("DELETE FROM vtiger_cvcolumnlist WHERE cvid IN (" . implode(',', $cvids) . ")");
$adb->query("DELETE FROM vtiger_customview WHERE cvid IN (" . implode(',', $cvids) . ")");
}
}
}
}
?>

25
vtlib/Vtiger/Language.php Normal file
View File

@ -0,0 +1,25 @@
<?php
/*+**********************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
************************************************************************************/
require_once('vtlib/Vtiger/LanguageImport.php');
/**
* Language Manager class for vtiger Modules.
* @package vtlib
*/
class Vtiger_Language extends Vtiger_LanguageImport {
/**
* Constructor
*/
function __construct() {
parent::__construct();
}
}
?>

View File

@ -0,0 +1,131 @@
<?php
/*+**********************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
************************************************************************************/
include_once('vtlib/Vtiger/Package.php');
/**
* Provides API to package vtiger CRM language files.
* @package vtlib
*/
class Vtiger_LanguageExport extends Vtiger_Package {
const TABLENAME = 'vtiger_language';
/**
* Constructor
*/
function __construct() {
parent::__construct();
}
/**
* Generate unique id for insertion
* @access private
*/
function __getUniqueId() {
global $adb;
return $adb->getUniqueID(self::TABLENAME);
}
/**
* 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), prefix VARCHAR(10), label VARCHAR(30), lastupdated DATETIME, sequence INT, 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,prefix,label,lastupdated,active) VALUES(?,?,?,?,?,?)',
Array($uniqueid, $langlabel,$langkey,$langlabel,date('Y-m-d H:i:s',time()), 1));
}
}
}
/**
* Register language pack information.
*/
static function register($prefix, $label, $name='', $isdefault=false, $isactive=true, $overrideCore=false) {
self::__initSchema();
$prefix = trim($prefix);
// We will not allow registering core language unless forced
if(strtolower($prefix) == 'en_us' && $overrideCore == false) return;
$useisdefault = ($isdefault)? 1 : 0;
$useisactive = ($isactive)? 1 : 0;
global $adb;
$checkres = $adb->pquery('SELECT * FROM '.self::TABLENAME.' WHERE prefix=?', Array($prefix));
$datetime = date('Y-m-d H:i:s');
if($adb->num_rows($checkres)) {
$id = $adb->query_result($checkres, 0, 'id');
$adb->pquery('UPDATE '.self::TABLENAME.' set label=?, name=?, lastupdated=?, isdefault=?, active=? WHERE id=?',
Array($label, $name, $datetime, $useisdefault, $useisactive, $id));
} else {
$uniqueid = self::__getUniqueId();
$adb->pquery('INSERT INTO '.self::TABLENAME.' (id,name,prefix,label,lastupdated,isdefault,active) VALUES(?,?,?,?,?,?,?)',
Array($uniqueid, $name, $prefix, $label, $datetime, $useisdefault, $useisactive));
}
self::log("Registering Language $label [$prefix] ... DONE");
}
/**
* De-Register language pack information
* @param String Language prefix like (de_de) etc
*/
static function deregister($prefix) {
$prefix = trim($prefix);
// We will not allow deregistering core language
if(strtolower($prefix) == 'en_us') return;
self::__initSchema();
global $adb;
$checkres = $adb->pquery('DELETE FROM '.self::TABLENAME.' WHERE prefix=?', Array($prefix));
self::log("Deregistering Language $prefix ... DONE");
}
/**
* 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->query('SELECT * FROM '.self::TABLENAME);
else $result = $adb->query('SELECT * FROM '.self::TABLENAME . ' WHERE active=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;
}
}
return $languageinfo;
}
}
?>

View File

@ -0,0 +1,138 @@
<?php
/*+**********************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
************************************************************************************/
include_once('vtlib/Vtiger/LanguageExport.php');
/**
* Provides API to import language into vtiger CRM
* @package vtlib
*/
class Vtiger_LanguageImport extends Vtiger_LanguageExport {
/**
* Constructor
*/
function __construct() {
parent::__construct();
}
function getPrefix() {
return (string)$this->_modulexml->prefix;
}
/**
* Initialize Import
* @access private
*/
function initImport($zipfile, $overwrite) {
$this->__initSchema();
$name = $this->getModuleNameFromZip($zipfile);
}
/**
* Import Module from zip file
* @param String Zip file name
* @param Boolean True for overwriting existing module
*/
function import($zipfile, $overwrite=false) {
$this->initImport($zipfile, $overwrite);
// Call module import function
$this->import_Language($zipfile);
}
/**
* Update Module from zip file
* @param Object Instance of Language (to keep Module update API consistent)
* @param String Zip file name
* @param Boolean True for overwriting existing module
*/
function update($instance, $zipfile, $overwrite=true) {
$this->import($zipfile, $overwrite);
}
/**
* Import Module
* @access private
*/
function import_Language($zipfile) {
$name = $this->_modulexml->name;
$prefix = $this->_modulexml->prefix;
$label = $this->_modulexml->label;
self::log("Importing $label [$prefix] ... STARTED");
$unzip = new Vtiger_Unzip($zipfile);
$filelist = $unzip->getList();
foreach($filelist as $filename=>$fileinfo) {
if(!$unzip->isdir($filename)) {
if(strpos($filename, '/') === false) continue;
$targetdir = substr($filename, 0, strripos($filename,'/'));
$targetfile = basename($filename);
$prefixparts = split('_', $prefix);
$dounzip = false;
if(is_dir($targetdir)) {
// Case handling for jscalendar
if(stripos($targetdir, 'jscalendar/lang') === 0
&& stripos($targetfile, "calendar-".$prefixparts[0].".js")===0) {
if(file_exists("$targetdir/calendar-en.js")) {
$dounzip = true;
}
}
// Case handling for phpmailer
else if(stripos($targetdir, 'modules/Emails/language') === 0
&& stripos($targetfile, "phpmailer.lang-$prefix.php")===0) {
if(file_exists("$targetdir/phpmailer.lang-en_us.php")) {
$dounzip = true;
}
}
// Handle javascript language file
else if(preg_match("/$prefix.lang.js/", $targetfile)) {
$corelangfile = "$targetdir/en_us.lang.js";
if(file_exists($corelangfile)) {
$dounzip = true;
}
}
// Handle php language file
else if(preg_match("/$prefix.lang.php/", $targetfile)) {
$corelangfile = "$targetdir/en_us.lang.php";
if(file_exists($corelangfile)) {
$dounzip = true;
}
}
}
if($dounzip) {
if($unzip->unzip($filename, $filename) !== false) {
self::log("Copying file $filename ... DONE");
} else {
self::log("Copying file $filename ... FAILED");
}
} else {
self::log("Copying file $filename ... SKIPPED");
}
}
}
if($unzip) $unzip->close();
self::register($prefix, $label, $name);
self::log("Importing $label [$prefix] ... DONE");
return;
}
}
?>