* @version 2.0.0
* @link http://aidanlister.com/2004/04/making-time-periods-readable/
* @param int number of seconds elapsed
* @param string which time periods to display
* @param bool whether to show zero time periods
*/
function time_duration($seconds, $use = null, $zeros = false,$short=true)
{
$segments = [];
$array = [];
// Define time periods
if (!$short){
$periods = array (
'years' => 31556926,
'Months' => 2629743,
'weeks' => 604800,
'days' => 86400,
'hours' => 3600,
'minutes' => 60,
'seconds' => 1
);
$space = " ";
if ($seconds <= 0) return "0 seconds";
}
else {
$periods = array (
'Y' => 31556926,
'M' => 2629743,
'w' => 604800,
'd' => 86400,
'h' => 3600,
'm' => 60,
's' => 1
);
$space = "";
if ($seconds <= 0) return "0s";
}
// Break into periods
$seconds = (float) $seconds;
foreach ($periods as $period => $value) {
if ($use && strpos($use, $period[0]) === false) {
continue;
}
$count = floor($seconds / $value);
if ($count == 0 && !$zeros) {
continue;
}
$segments[$period] = $count; //crmv@55210
$seconds = $seconds % $value;
}
// Build the string
foreach ($segments as $key => $value) {
if (!$short){
$segment_name = substr($key, 0, -1);
}
else {
$segment_name = $key;
}
$segment = $value.$space.$segment_name;
if (!$short){
if ($value != 1) {
$segment .= 's';
}
}
$array[] = $segment;
}
$str = implode(' ', $array);
return $str;
}
//crmv@18338 end
//crmv@18592
function getParentTabs()
{
global $adb,$table_prefix;
$return = [];
$sql = 'SELECT * FROM '.$table_prefix.'_parenttab ORDER BY sequence';
$result = $adb->query($sql);
while($row = $adb->fetch_array($result))
$return[$row['parenttabid']] = array('parenttab_label'=>$row['parenttab_label'],'hidden'=>$row['hidden']);
return $return;
}
function getMenuLayout() { /* crmv@33465 crmv@47905bis */
global $adb;
if (!$adb->table_exist('tbl_s_menu')){
return array();
}
$cache = Cache::getInstance('getMenuLayout');
$return = $cache->get();
if ($return === false) {
$result = $adb->query('select type from tbl_s_menu');
if ($result) {
$return = array('type'=>$adb->query_result($result,0,'type'));
$cache->set($return);
}
}
return $return;
}
function getMenuModuleList($otherAll=false) { /* crmv@30356 crmv@32217 crmv@31250 crmv@42707 crmv@47905bis */
global $adb,$table_prefix;
require('user_privileges/requireUserPrivileges.php');
$cache = Cache::getInstance('getMenuModuleList');
$tmp = $cache->get();
if ($tmp === false) {
$tmp = array();
$sql = 'SELECT '.$table_prefix.'_tab.tabid,'.$table_prefix.'_tab.name,tbl_s_menu_modules.fast,tbl_s_menu_modules.sequence FROM '.$table_prefix.'_tab
INNER JOIN (SELECT DISTINCT tabid FROM '.$table_prefix.'_parenttabrel) parenttabrel ON parenttabrel.tabid = '.$table_prefix.'_tab.tabid
LEFT JOIN tbl_s_menu_modules ON '.$table_prefix.'_tab.tabid = tbl_s_menu_modules.tabid
WHERE '.$table_prefix.'_tab.presence = 0
ORDER BY tbl_s_menu_modules.fast, tbl_s_menu_modules.sequence';
$res = $adb->query($sql);
while($row=$adb->fetchByAssoc($res)) {
$tmp[$row['tabid']] = $row;
}
$cache->set($tmp);
}
$module_list = array();
foreach($tmp as $tabid => $info) {
if ($profileGlobalPermission[2] == 0 || $profileGlobalPermission[1] == 0 || $profileTabsPermission[$tabid] == 0) {
$module_list[$tabid] = $info;
}
}
$max_menu = 0;
$module_list_fast = array();
$module_list_other = array();
foreach($module_list as $id => $info) {
$info['index_url'] = "index.php?module={$info['name']}&action=index";
// modules without list
if (!in_array($info['name'], array('Home'))) {
$info['list_url'] = $info['index_url'];
}
// modules without standard EditView
if (!in_array($info['name'], array('Home', 'Messages', 'PDFMaker', 'Rss', 'Sms', 'Fax', 'RecycleBin', 'Charts', 'Portal'))) {//crmv@208472
$info['create_url'] = "index.php?module={$info['name']}&action=EditView";
}
// custom editview
if ($info['name'] == 'Messages') {
$info['create_url'] = "index.php?module=Emails&action=EmailsAjax&file=EditView";
}
$mod_transl = getTranslatedString($info['name'],$info['name']);
$app_transl = getTranslatedString($info['name'],'APP_STRINGS');
if (isMobile()){
if ($info['fast'] == 1 && $max_menu < 5) {
$module_list_fast[] = $info;
$max_menu ++;
} else {
($app_transl === $info['name'] || $info['name'] === 'PBXManager') ? $info['translabel'] = $mod_transl : $info['translabel'] = $app_transl;
if ($mod_transl != $info['name'] && $mod_transl != $app_transl) $info['translabel'] = $mod_transl;
$module_list_other[] = $info;
}
} else {
($app_transl === $info['name'] || $info['name'] === 'PBXManager') ? $info['translabel'] = $mod_transl : $info['translabel'] = $app_transl;
if ($mod_transl != $info['name'] && $mod_transl != $app_transl) $info['translabel'] = $mod_transl;
if ($info['fast'] == 1) {
$module_list_fast[] = $info;
}
if ($otherAll) {
$module_list_other[] = $info;
} else {
if ($info['fast'] != 1) {
$module_list_other[] = $info;
}
}
}
}
usort($module_list_other, function($a, $b) {
return ($a['translabel'] > $b['translabel']);
});
return array($module_list_fast,$module_list_other);
}
//crmv@18592e
//crmv@20211 crmv@46109 crmv@59867
function calculateCalColor() {
global $adb,$table_prefix;
$query = 'SELECT tbl_s_cal_color.id AS "idcolor", color, COUNT(color) AS conteggio
FROM tbl_s_cal_color
INNER JOIN '.$table_prefix.'_users ON tbl_s_cal_color.color = '.$table_prefix.'_users.cal_color
GROUP BY tbl_s_cal_color.color, tbl_s_cal_color.id
UNION
SELECT tbl_s_cal_color.id AS "idcolor", color, 0 AS conteggio
FROM tbl_s_cal_color
WHERE color NOT IN( SELECT color
FROM tbl_s_cal_color
INNER JOIN '.$table_prefix.'_users ON tbl_s_cal_color.color = '.$table_prefix.'_users.cal_color
GROUP BY tbl_s_cal_color.color)
ORDER BY conteggio,"idcolor"';
$result = $adb->limitQuery($query,0,1);
if ($result)
return $adb->query_result($result,0,'color');
}
//crmv@20211e crmv@46109e crmv@59867e
//crmv@23515 crmv@52561
function getCalendarRelatedToModules($skip_modules=true) {
global $adb,$table_prefix;
$moduleInstance = Vtecrm_Module::getInstance('Calendar');
$query = "SELECT ".$table_prefix."_tab.name FROM ".$table_prefix."_relatedlists
INNER JOIN ".$table_prefix."_tab ON ".$table_prefix."_relatedlists.tabid = ".$table_prefix."_tab.tabid
WHERE related_tabid = ".$moduleInstance->id." AND ".$table_prefix."_relatedlists.name IN ('get_activities','get_history')";
if ($skip_modules) {
$query .= " AND ".$table_prefix."_tab.name <> 'Contacts'";
}
$query .= " GROUP BY ".$table_prefix."_tab.name";
$result = $adb->query($query);
$modules = array();
while($row=$adb->fetchByAssoc($result)) {
$modules[] = $row['name'];
}
return $modules;
}
//crmv@23515e crmv@52561e
function isModuleInstalled($module) { /* crmv@22700 crmv@27624 crmv@25671 crmv@47905bis */
global $adb,$table_prefix;
static $rcache = array();
if (isset($rcache[$module])) return $rcache[$module]; // crmv@162449
if (empty($adb) || !Vtecrm_Utils::CheckTable($table_prefix.'_tab')) return false;
// these modules are not in vte_tab, but they are always present
if (in_array($module, array('Administration','com_workflow','CustomView','Help','Import','PickList','Picklistmulti','Settings','Yahoo'))) return true;//crmv@207901
$cache = Cache::getInstance('installed_modules');
$installed_modules = $cache->get();
if ($installed_modules === false) {
$installed_modules = array();
$result = $adb->query("SELECT name FROM {$table_prefix}_tab");
if ($result && $adb->num_rows($result) > 0) {
while($row=$adb->fetchByAssoc($result)) {
$installed_modules[] = $row['name'];
}
}
$cache->set($installed_modules);
}
// crmv@162449
$rcache[$module] = in_array($module,$installed_modules);
return $rcache[$module];
// crmv@162449e
}
//crmv@24568
function get_short_language(){
$langs = explode('_',VteSession::get('authenticated_user_language'));
return $langs[0];
}
//crmv@24568e
//crmv@24715
function fix_query_advanced_filters($module,&$query,$columns_to_check=false,$scope=''){ // crmv@129114
global $adb,$table_prefix;
if ($columns_to_check === false){
$columns_to_check = Zend_Json::decode(getAdvancedresList($module,'columns'));
}
$tabid = getTabid($module); // crmv@167125
$query = preg_replace("/[\n\r\t]+/"," ",$query); //crmv@20049
if (is_array($columns_to_check)) {
foreach ($columns_to_check as $_to_split){
$splitted=explode(":",$_to_split);
$tablename = trim($splitted[0]);
$columnname = trim($splitted[1]);
$fieldname = trim($splitted[2]); //crmv@31423
$uitype = 10; // crmv@167125 - changed later
if ($columnname == 'smownerid') $found_users = true; //crmv@82220
//crmv@72942 crmv@184929
$sql = "SELECT {$table_prefix}_entityname.tablename, {$table_prefix}_entityname.fieldname, {$table_prefix}_field.fieldid
FROM {$table_prefix}_field
INNER JOIN {$table_prefix}_fieldmodulerel ON {$table_prefix}_field.fieldid = {$table_prefix}_fieldmodulerel.fieldid
INNER JOIN {$table_prefix}_entityname ON {$table_prefix}_entityname.modulename = {$table_prefix}_fieldmodulerel.relmodule
WHERE {$table_prefix}_field.tablename = ? AND {$table_prefix}_field.columnname = ? AND {$table_prefix}_field.fieldname = ? AND {$table_prefix}_field.uitype = ?";
$result = $adb->pquery($sql, array($tablename, $columnname, $fieldname, '10'));
if ($result && $adb->num_rows($result) > 0) {
$tablename = $adb->query_result($result, 0, 'tablename');
$entity_fieldname = explode(',',$adb->query_result($result, 0, 'fieldname'));
$entity_fieldname = $entity_fieldname[0];
$fieldname = $entity_fieldname;
$fieldid = $adb->query_result_no_html($result, 0, 'fieldid'); // crmv@184929
// crmv@184929e
$result = $adb->pquery("select columnname from {$table_prefix}_field where tablename=? and fieldname=?", array($tablename, $fieldname));
if ($result && $adb->num_rows($result) > 0) {
$columnname = $adb->query_result($result, 0, 'columnname');
}
// crmv@167125 - check for new user fields
} else {
$sql =
"SELECT f.uitype, fieldid
FROM {$table_prefix}_field f
WHERE f.tabid = ? AND f.fieldname = ?";
$res = $adb->pquery($sql, array($tabid, $fieldname));
if ($res && $adb->num_rows($res) > 0) {
$uitype = intval($adb->query_result_no_html($res, 0, 'uitype'));
$fieldid = intval($adb->query_result_no_html($res, 0, 'fieldid'));
}
}
//crmv@72942e crmv@167125e
if (!preg_match("/join\s+$tablename\s+on/i", $query) && !preg_match("/from\s+$tablename\s+/i", $query)) { // crmv@167791 crmv@168197
$obj = CRMEntity::getInstance($module);
$module_table=$obj->table_name;
$module_pk=$obj->tab_name_index[$obj->table_name];
//la tabella � del modulo corrente
if (in_array($tablename,array_keys($obj->tab_name_index))){
$join_check = " left join $tablename on $tablename.{$obj->tab_name_index[$tablename]} = $module_table.$module_pk ";
// crmv@167125
// check if it's a new user field
$wsfield = WebserviceField::fromQueryResult($adb,$adb->pquery('select * from '.$table_prefix.'_field where tabid = ? and fieldname = ?',array($tabid,$fieldname)),0);
if ($wsfield->getFieldDataType() == 'reference') {
$fieldid = $wsfield->getFieldId();
$reflist = $wsfield->getReferenceList();
if (in_array('Users', $reflist)) {
$join_check .= "LEFT JOIN {$table_prefix}_users {$table_prefix}_users_fld_{$fieldid} ON {$table_prefix}_users_fld_{$fieldid}.id = $tablename.$columnname ";
$join_check .= "LEFT JOIN {$table_prefix}_groups {$table_prefix}_groups_fld_{$fieldid} ON {$table_prefix}_groups_fld_{$fieldid}.groupid = $tablename.$columnname ";
}
}
// crmv@167125e
$query = preg_replace('/\swhere\s/i', " $join_check where ", $query, 1);
}
else{
//cerco il modulo collegato
$sql = "SELECT ".$table_prefix."_tab.name FROM ".$table_prefix."_field
INNER JOIN ".$table_prefix."_tab ON ".$table_prefix."_tab.tabid = ".$table_prefix."_field.tabid
WHERE tablename=? and fieldname=?";
$params = Array($tablename,$fieldname);
$result = $adb->pquery($sql,$params);
if ($result && $adb->num_rows($result)==1){
$rel_module = $adb->query_result($result,0,'name');
$rel_obj = CRMEntity::getInstance($rel_module);
$relmodule_table=$obj->table_name;
$relmodule_pk=$obj->tab_name_index[$obj->table_name];
$tables=Array();
$fields=Array();
$reltables = getRelationTables($module,$rel_module);
// echo "";
// print_r($reltables);die;
foreach($reltables as $key=>$value){
$tables[]=$key;
$fields[] = $value;
}
$relation_table = $tables[0];
$relation_table1 = $tables[1];
$prifieldname = $fields[0][0];
$secfieldname = $fields[0][1];
$relation_table1_key = $fields[1];
if ($relation_table1){ //relazione n a n
//TODO:gestire la tabella vte_crmentityrel!
if (stripos($query," join $relation_table ")===false){
$join_check = " left join $relation_table on $relation_table.$prifieldname = $module_table.$module_pk ";
$query = preg_replace('/\swhere\s/i', " $join_check where ", $query, 1);
}
$join_check = " left join $tablename on $tablename.{$rel_obj->tab_name_index[$tablename]} = $relation_table.$secfieldname ";
$query = preg_replace('/\swhere\s/i', " $join_check where ", $query, 1);
}
else{ //relazione 1 a n
if (stripos($query," join $relation_table ")===false && stripos($query," from $relation_table ")===false){
$join_check = " left join $relation_table on $relation_table.$prifieldname = $relmodule_table.$relmodule_pk ";
$query = preg_replace('/\swhere\s/i', " $join_check where ", $query, 1);
}
if ($tablename != $relmodule_table){
$join_check = " left join $tablename on $tablename.{$rel_obj->tab_name_index[$tablename]} = $relation_table.$secfieldname ";
$query = preg_replace('/\swhere\s/i', " $join_check where ", $query, 1);
}
}
}
}
}
// crmv@167125 crmv@184929
$newjoins = '';
if (in_array($uitype, array(50,51,52,54)) && $fieldname != 'smownerid') {
if (stripos($query," JOIN {$table_prefix}_users {$table_prefix}_users_fld_{$fieldid}") === false) { // crmv@203079
$newjoins .= "LEFT JOIN {$table_prefix}_users {$table_prefix}_users_fld_{$fieldid} ON {$table_prefix}_users_fld_{$fieldid}.id = $tablename.$columnname ";
}
if (stripos($query," JOIN {$table_prefix}_groups {$table_prefix}_groups_fld_{$fieldid}") === false) { // crmv@203079
$newjoins .= "LEFT JOIN {$table_prefix}_groups {$table_prefix}_groups_fld_{$fieldid} ON {$table_prefix}_groups_fld_{$fieldid}.groupid = $tablename.$columnname ";
}
// crmv@167125e
} elseif ($uitype == 10) {
$alias = "entityname_fld_".$fieldid;
if (stripos($query,"join {$table_prefix}_entity_displayname {$alias}") === false) {
$newjoins .= "LEFT JOIN {$table_prefix}_entity_displayname {$alias} ON {$alias}.crmid = {$splitted[0]}.{$splitted[1]} ";
}
}
if ($newjoins) {
$query = preg_replace('/\swhere\s/i', " $newjoins where ", $query, 1);
}
// crmv@184929e
}
//crmv@82220
if ($found_users == true) {
if (stripos($query," join {$table_prefix}_users")===false && stripos($query," from {$table_prefix}_users")===false){
$join_check = " inner join {$table_prefix}_users on {$table_prefix}_users.id = {$table_prefix}_crmentity{$scope}.smownerid"; // crmv@129114
$query = preg_replace('/\swhere\s/i', " $join_check where ", $query, 1);
}
if (stripos($query," join {$table_prefix}_groups")===false && stripos($query," from {$table_prefix}_groups")===false){
$join_check = " inner join {$table_prefix}_groups on {$table_prefix}_groups.groupid = {$table_prefix}_crmentity{$scope}.smownerid"; // crmv@129114
$query = preg_replace('/\swhere\s/i', " $join_check where ", $query, 1);
}
}
//crmv@82220e
}
}
//crmv@24715e
//crmv@27096
function saveListViewCheck($module,$ids) {
global $adb, $current_user;
$moduleInstance = Vtecrm_Module::getInstance($module);
$adb->pquery('delete from vte_listview_check where userid = ? and tabid = ?',array($current_user->id,$moduleInstance->id));
if (!is_array($ids)) {
if (strpos($ids,';') !== false) {
$ids = explode(';',$ids);
} elseif (strpos($ids,',') !== false) {
$ids = explode(',',$ids);
} else {
$ids = array($ids);
}
}
if (is_array($ids)) {
$ids = array_filter($ids);
}
if (!empty($ids)) {
foreach($ids as $id) {
$adb->pquery('insert into vte_listview_check (userid,tabid,crmid) values (?,?,?)',array($current_user->id,$moduleInstance->id,$id));
}
}
}
function getListViewCheck($module) {
global $adb, $current_user;
$moduleInstance = Vtecrm_Module::getInstance($module);
$result = $adb->pquery('SELECT crmid FROM vte_listview_check WHERE userid = ? AND tabid = ?',array($current_user->id,$moduleInstance->id));
$ids = array();
if ($result && $adb->num_rows($result) > 0) {
while($row=$adb->fetchByAssoc($result)) {
$ids[] = $row['crmid'];
}
}
return $ids;
}
//crmv@27096e
//crmv@2043m
// returns field value from fieldid
function getFieldValue($fieldid, $crmid) {
global $adb,$table_prefix;
$res = $adb->pquery(
"select
".$table_prefix."_tab.name as modulename,
fieldid, fieldname, tablename, columnname
from ".$table_prefix."_field
inner join ".$table_prefix."_tab on ".$table_prefix."_tab.tabid = ".$table_prefix."_field.tabid
where fieldid=? and ".$table_prefix."_field.presence in (0,2)",
array($fieldid)
);
if ($res && $adb->num_rows($res) > 0) {
$row = $adb->FetchByAssoc($res, -1, false);
$focus = CRMEntity::getInstance($row['modulename']);
if (empty($focus)) return null;
$indexname = $focus->tab_name_index[$row['tablename']];
if (empty($indexname)) return null;
if ($row['tablename'] != $table_prefix.'_crmentity') {
$join = "inner join ".$table_prefix."_crmentity on ".$table_prefix."_crmentity.crmid = {$row['tablename']}.$indexname";
} else {
$join = "";
}
$res2 = $adb->query("select {$row['tablename']}.{$row['columnname']} as fieldval from {$row['tablename']} $join where ".$table_prefix."_crmentity.deleted = 0 and {$row['tablename']}.$indexname = $crmid"); // crmv@42752
if ($res2) {
$value = $adb->query_result($res2, 0, 'fieldval');
return $value;
}
}
return null;
}
//crmv@2043me
//crmv@27711
function getHideTab($mode='all') {
global $adb;
$result = $adb->query('select * from vte_hide_tab');
$return = array();
if ($result && $adb->num_rows($result) > 0) {
while($row=$adb->fetchByAssoc($result)) {
$tabid = $row['tabid'];
$hide_module_manager = $row['hide_module_manager'];
if ($hide_module_manager == '1') {
$return['hide_module_manager'][] = $tabid;
}
$hide_profile = $row['hide_profile'];
if ($hide_profile == '1') {
$return['hide_profile'][] = $tabid;
}
$hide_report = $row['hide_report'];
if ($hide_report == '1') {
$return['hide_report'][] = $tabid;
}
}
}
if (!empty($return)) {
if ($mode != 'all') {
$return = $return[$mode];
}
}
return $return;
}
//crmv@27711e
//crmv@29079
function getDefaultUserAvatar($mode='') {
global $theme;
if ($mode == 'menu') {
return resourcever("no_avatar_$mode.png");
} else {
return resourcever('no_avatar.png');
}
}
function getUserAvatar($id,$mode='') {
global $current_user, $table_prefix;
$avatar = '';
if ($id == $current_user->id) {
$avatar = $current_user->column_fields['avatar'];
} elseif ($id != '') {
global $adb;
$result = $adb->pquery('SELECT avatar FROM '.$table_prefix.'_users WHERE id = ?',array($id));
if ($result && $adb->num_rows($result) > 0) {
$avatar = $adb->query_result($result,0,'avatar');
}
}
if ($avatar == '') {
$avatar = getDefaultUserAvatar($mode);
}
return $avatar;
}
function getUserAvatarImg($id,$params='',$mode='') {
$imgpath = getUserAvatar($id,$mode);
if (!empty($imgpath)) {
$name = getUserFullName($id);
return "
";
}
}
function getSingleModuleName($module,$record='') {
if ($module == 'Calendar' && $record != '') {
global $adb,$table_prefix;
$result = $adb->pquery('SELECT activitytype FROM '.$table_prefix.'_activity WHERE activityid = ?',array($record));
if ($result && $adb->num_rows($result) > 0) {
$activitytype = getTranslatedString($adb->query_result($result,0,'activitytype'),$module);
}
if ($activitytype != '') {
return $activitytype;
}
}
$single_module = getTranslatedString('SINGLE_'.$module,$module);
if (in_array($single_module,array('','SINGLE_'.$module))) {
$single_module = getTranslatedString($module,$module);
}
return $single_module;
}
//crmv@29079e
//crmv@100731
function getGroupAvatar($id='',$mode='') {
$avatar = getDefaultGroupAvatar($mode);
return $avatar;
}
function getDefaultGroupAvatar($mode='') {
return resourcever('ico-groups_small.png');
}
//crmv@100731e
//crmv@29615
function getDisplayFieldName($uitype,$fieldname) {
if ($uitype == '10')
$fieldname = $fieldname.'_display';
elseif ($uitype == '77')
$fieldname = 'assigned_user_id1';
elseif ($uitype == '357')
$fieldname = 'parent_name';
elseif ($uitype == '98')
$fieldname = 'role_name';
elseif ($uitype == '30')
$fieldname = 'set_reminder';
return $fieldname;
}
//crmv@29615e
//crmv@30356
function isMobile() {
if (!VteSession::hasKey('isMobileClient')) {
$user_agent = $_SERVER['HTTP_USER_AGENT'];
$mobile_agents = Array(
"acer",
"alcatel",
"android",
"applewebkit/525",
"applewebkit/532",
"asus",
"blackberry",
"hitachi",
"htc",
"huawei",
"ipad",
"ipaq",
"ipod",
"lg",
"nintendo",
"nokia",
"panasonic",
"philips",
"phone",
"playstation",
"sanyo",
"samsung",
"sharp",
"siemens",
"sony",
"symbian",
"tablet",
"toshiba",
);
$is_mobile = false;
foreach ($mobile_agents as $device) {
if (stristr($user_agent, $device)) {
$is_mobile = true;
break;
}
}
/*
if(array_search ($user_agent,$mobile_agents)){
$is_mobile = true;
}
*/
VteSession::set('isMobileClient', $is_mobile);
}
return VteSession::get('isMobileClient');
}
//crmv@30356e
//crmv@17001
function getCalendarColors() {
global $adb,$current_user,$table_prefix;
$arr = array();
$i = 0;
$arr[$current_user->id] = $i;
//$res = $adb->query("SELECT id FROM vte_users WHERE id <> ".$current_user->id);
$res = $adb->query("SELECT id FROM ".$table_prefix."_users ");
if ($res && $adb->num_rows($res)>0) {
while($row = $adb->fetchByAssoc($res)) {
//$i++; //crm@20211
$arr[$row['id']] = $i++;
}
}
return $arr;
}
function getUserColor($id) {
global $calendar_colors;
if ($calendar_colors == '') $calendar_colors = getCalendarColors();
return $calendar_colors[$id];
}
//crmv@17001e
//crmv@30967
function getEntityFolder($folderid) {
global $adb, $table_prefix;
$res = $adb->pquery("select * from {$table_prefix}_crmentityfolder where folderid = ?", array($folderid));
if ($res !== false) {
return $adb->fetchByAssoc($res);
} else {
return false;
}
}
function getEntityFoldersByName($foldername = null, $module = null) {
global $adb, $table_prefix;
$params = array();
$conds = array();
$sql = "select * from {$table_prefix}_crmentityfolder";
if (!is_null($foldername) || !is_null($module)) {
$sql .= ' where ';
}
if (!is_null($foldername)) {
$conds[] = ' foldername = ? ';
$params[] = $foldername;
}
if (!is_null($module)) {
$conds[] = ' tabid = ? ';
$params[] = getTabId($module);
}
$sql .= implode(' and ', $conds);
$sql .= ' order by foldername';
$res = $adb->pquery($sql, $params);
if ($res !== false) {
$ret = array();
while ($row = $adb->fetchByAssoc($res)) {
//crmv@90004
$row['editable'] = (empty($row['state']) || $row['state'] == 'CUSTOMIZED');
if (in_array($row['foldername'],array('Default','Message attachments','Esempi'))) $row['editable'] = false; // TODO : usare attributo nella classe del modulo
//crmv@90004e
$ret[] = $row;
}
return $ret;
} else {
return false;
}
}
function addEntityFolder($module, $foldername, $description = '', $creator = 1, $state = '', $sequence = 0) {
global $adb, $table_prefix;
$tabid = getTabid($module);
// try to do a direct query
if (empty($tabid)) {
$res = $adb->pquery("select tabid from {$table_prefix}_tab where name = ?", array($module));
if ($res && $adb->num_rows($res) > 0) $tabid = $adb->query_result($res, 0, 'tabid');
}
if (empty($tabid)) return false;
$folderid = $adb->getUniqueID($table_prefix."_crmentityfolder");
$params = array($folderid, $tabid, $creator, $foldername, $description, $state, $sequence);
$res = $adb->pquery("insert into {$table_prefix}_crmentityfolder (folderid, tabid, createdby, foldername, description, state, sequence) values (".generateQuestionMarks($params).")", $params);
if ($res !== false)
return $folderid;
else
return false;
}
function editEntityFolder($folderid, $foldername, $description = null, $state = null) {
global $adb, $table_prefix;
$params = array($foldername);
$sql = "update {$table_prefix}_crmentityfolder set foldername = ?";
if (!is_null($description)) {
$sql .= ', description = ?';
$params[] = $description;
}
if (!is_null($state)) {
$sql .= ', state = ?';
$params[] = $state;
}
$sql .= " where folderid = ?";
$params[] = $folderid;
$res = $adb->pquery($sql, $params);
if ($res !== false) return $folderid; else return false;
}
function deleteEntityFolder($folderid) {
global $adb, $table_prefix;
$res = $adb->pquery("delete from {$table_prefix}_crmentityfolder where folderid = ?", array($folderid));
if ($res !== false)
return $folderid;
else
return false;
}
//crmv@30967e
//crmv@34627
function getRelationFields($module, $relmodules, $crmid='', $filter_ids=array(), $reportid='') {
global $adb, $table_prefix;
static $return = array();
if (empty($crmid) || (!empty($crmid) && !isset($return[$module][$relmodules][$crmid]))) {
// special uitypes for relations
$uitype_rel = array(
// removed 51
'57' => "Contacts",
'58' => "Campaigns",
'59' => "Products",
// removed 73
'75' => "Vendors",
'81' => "Vendors",
'76' => "Potentials",
'78' => "Quotes",
'80' => "SalesOrder",
// '68' => "*", TODO: parenti_id in tickets
);
$ret = array();
$fieldids = array();
if (!is_array($relmodules)) $relmodules = array($relmodules);
$relmodules_noself = array_diff($relmodules, array($module));
$moduleid = getTabid($module);
$rel_moduleid = array_map('getTabid', $relmodules);
$rel_moduleid_noself = array_diff($rel_moduleid, array($moduleid));
// first go with field-relations (solo uitype 10)
// TODO: che succede se in relmodules c'� module?
$params = array($module);
$params = array_merge($params, $relmodules, array($module), $relmodules_noself);
$query = '
select
'.$table_prefix.'_fieldmodulerel.fieldid, relmodule, 1 as "direct", '.$table_prefix.'_field.columnname, '.$table_prefix.'_field.tablename, '.$table_prefix.'_field.fieldname
from '.$table_prefix.'_fieldmodulerel
inner join '.$table_prefix.'_field on '.$table_prefix.'_field.fieldid = '.$table_prefix.'_fieldmodulerel.fieldid
where
module = ? and relmodule in ('.generateQuestionMarks($relmodules).')
union
select
'.$table_prefix.'_fieldmodulerel.fieldid, module as "relmodule", 0 as "direct", '.$table_prefix.'_field.columnname, '.$table_prefix.'_field.tablename, '.$table_prefix.'_field.fieldname
from '.$table_prefix.'_fieldmodulerel
inner join '.$table_prefix.'_field on '.$table_prefix.'_field.fieldid = '.$table_prefix.'_fieldmodulerel.fieldid
where
relmodule = ? and module in ('.generateQuestionMarks($relmodules_noself).')';
// add select for special uitypes (direct relation)
$uilist = array_intersect($uitype_rel, $relmodules);
if (count($uilist) > 0) {
$casemod = 'case';
foreach ($uilist as $ui=>$rmod) {
$casemod .= " when {$table_prefix}_field.uitype = $ui then '$rmod'";
}
$casemod .= ' end';
$query .= '
union
select
'.$table_prefix.'_field.fieldid, '.$casemod.' as "relmodule", 1 as "direct", '.$table_prefix.'_field.columnname, '.$table_prefix.'_field.tablename, '.$table_prefix.'_field.fieldname
from '.$table_prefix.'_field
inner join '.$table_prefix.'_tab on '.$table_prefix.'_tab.tabid = '.$table_prefix.'_field.tabid
where
'.$table_prefix.'_field.tabid = ?
and '.$table_prefix.'_field.uitype in ('.generateQuestionMarks($uilist).')
';
$params[] = $moduleid;
$params = array_merge($params, array_keys($uilist));
}
// special uitypes - (indirect relations)
$uilist = array_intersect($uitype_rel, array($module));
if (count($uilist) > 0) {
$query .= "
union
select
{$table_prefix}_field.fieldid, {$table_prefix}_tab.name as \"relmodule\", 0 as \"direct\", {$table_prefix}_field.columnname, {$table_prefix}_field.tablename, {$table_prefix}_field.fieldname
from {$table_prefix}_field
inner join {$table_prefix}_tab on {$table_prefix}_tab.tabid = {$table_prefix}_field.tabid
where
{$table_prefix}_field.tabid in (".generateQuestionMarks($rel_moduleid_noself).")
and {$table_prefix}_field.uitype in (".generateQuestionMarks($uilist).')
';
$params = array_merge($params, $rel_moduleid_noself);
$params = array_merge($params, array_keys($uilist));
}
//$startTime = microtime();
$res = $adb->pquery($query, $params);
if ($res) {
while ($row = $adb->FetchByAssoc($res, -1, false)) {
if ($row['direct']) {
$fieldids['direct'][$row['fieldid']] = array('module'=>$row['relmodule'],'tablename'=>$row['tablename'],'columnname'=>$row['columnname'],'fieldname'=>$row['fieldname']);
} else {
// reverse relation, search for right value
$ids = searchFieldValue($row['fieldid'], $crmid);
if (!empty($ids) && !empty($filter_ids)) {
$ids = array_values(array_intersect($ids,$filter_ids));
}
$fieldids['indirect'][$row['fieldid']] = array('module'=>$row['relmodule'],'tablename'=>$row['tablename'],'columnname'=>$row['columnname'],'fieldname'=>$row['fieldname']
,'ids'=>$ids // this can be slow!!
);
}
}
}
//$endTime = microtime();
//list($usec, $sec) = explode(" ", $endTime);
//$endTime = ((float)$usec + (float)$sec);
//list($usec, $sec) = explode(" ", $startTime);
//$startTime = ((float)$usec + (float)$sec);
//$deltaTime = round($endTime - $startTime,2);
//echo('
Field Query: '.$deltaTime.' seconds.
');
//and finally with general relation table
$params = array();
$params = array_merge($params, array($module), $relmodules);
$query = '
select
relcrmid, relmodule
from '.$table_prefix.'_crmentityrel
where
module = ? and relmodule in ('.generateQuestionMarks($relmodules).')';
if (!empty($crmid)) {
$query .= ' and crmid = ?';
$params[] = $crmid;
}
$params = array_merge($params, array($module), $relmodules);
$query .= '
union
select
crmid AS "relcrmid", module AS "relmodule"
from '.$table_prefix.'_crmentityrel
where
relmodule = ? and module in ('.generateQuestionMarks($relmodules).')';
if (!empty($crmid)) {
$query .= ' and relcrmid = ?';
$params[] = $crmid;
}
if (in_array('Calendar', $relmodules)) {
$query .= "
union
select
activityid as \"relcrmid\",
\"Calendar\" as \"relmodule\"
from {$table_prefix}_seactivityrel
inner join {$table_prefix}_crmentity on {$table_prefix}_crmentity.crmid = {$table_prefix}_seactivityrel.activityid and {$table_prefix}_crmentity.deleted = 0
where {$table_prefix}_crmentity.setype not in ('Emails')"; // crmv@152701
if (!empty($crmid)) {
$query .= " and {$table_prefix}_seactivityrel.crmid = ?";
$params[] = $crmid;
}
}
// TODO: gestire email/fax/sms
if ($module == 'Products' || in_array('Products', $relmodules)) {
$inventory_modules = getInventoryModules(); // crmv@64542
if ($module == 'Products') {
$reltable = "{$table_prefix}_seproductsrel";
$relcrmid = "$reltable.crmid";
$relmodule = "$reltable.setype";
$wherecrmid = "$reltable.productid";
$crmentity_join_id = "$reltable.productid";
foreach($relmodules as $relmod) {
if (in_array($relmod,$inventory_modules)) {
$reltable = "{$table_prefix}_inventoryproductrel";
$relcrmid = "$reltable.id";
$relmodule = "{$table_prefix}_crmentity.setype";
$wherecrmid = "$reltable.productid";
$crmentity_join_id = "$reltable.id";
}
}
} else {
if (in_array($module,$inventory_modules)) {
$reltable = "{$table_prefix}_inventoryproductrel";
$relcrmid = "$reltable.productid";
$relmodule = "\"Products\"";
$wherecrmid = "$reltable.id";
$crmentity_join_id = "$reltable.productid";
} else {
$reltable = "{$table_prefix}_seproductsrel";
$relcrmid = "$reltable.productid";
$relmodule = "\"Products\"";
$wherecrmid = "$reltable.crmid";
$crmentity_join_id = "$reltable.productid";
}
}
$query .= "
union
select
$relcrmid as \"relcrmid\",
$relmodule as \"relmodule\"
from $reltable
inner join {$table_prefix}_crmentity on {$table_prefix}_crmentity.crmid = $crmentity_join_id and {$table_prefix}_crmentity.deleted = 0";
if (!empty($crmid)) {
$query .= " and $wherecrmid = ?";
$params[] = $crmid;
}
}
if ($module == 'Documents' || in_array('Documents', $relmodules)) {
if ($module == 'Documents') {
$relcrmid = "{$table_prefix}_senotesrel.crmid";
$relmodule = "{$table_prefix}_crmentity.setype";
$wherecrmid = "notesid";
} else {
$relcrmid = "notesid";
$relmodule = "\"Documents\"";
$wherecrmid = "{$table_prefix}_senotesrel.crmid";
}
$query .= "
union
select
$relcrmid as \"relcrmid\",
$relmodule as \"relmodule\"
from {$table_prefix}_senotesrel
inner join {$table_prefix}_crmentity on {$table_prefix}_crmentity.crmid = $relcrmid and {$table_prefix}_crmentity.deleted = 0";
if (!empty($crmid)) {
$query .= " and $wherecrmid = ?";
$params[] = $crmid;
}
}
$query .= " ORDER BY relcrmid";
// seticketsrel non serve pi�
// anche {$table_prefix}_campaign*rel sono vecchie
//$startTime = microtime();
$res = $adb->pquery($query, $params);
$related = array();
if ($res) {
while ($row = $adb->FetchByAssoc($res, -1, false)) {
if (!in_array($row['relmodule'],$relmodules)) {
continue;
}
if (empty($crmid)) {
if (!in_array($row['relmodule'],$related))
$related[] = $row['relmodule'];
} else {
$related[$row['relmodule']][] = $row['relcrmid'];
}
if (!empty($related[$row['relmodule']]) && !empty($filter_ids)) {
$related[$row['relmodule']] = array_values(array_intersect($related[$row['relmodule']],$filter_ids)); //filtro i valori collegati al record con quelli che rispettano il filtro del report
}
}
}
//$endTime = microtime();
//list($usec, $sec) = explode(" ", $endTime);
//$endTime = ((float)$usec + (float)$sec);
//list($usec, $sec) = explode(" ", $startTime);
//$startTime = ((float)$usec + (float)$sec);
//$deltaTime = round($endTime - $startTime,2);
//echo('Related Query: '.$deltaTime.' seconds.
');
$retrn = array('fields'=>$fieldids,'related'=>$related);
if (empty($crmid)) {
return $retrn;
} else {
$relmodules = $relmodules[0];
$return[$module][$relmodules][$crmid] = $retrn;
}
}
return $return[$module][$relmodules][$crmid];
}
function searchFieldValue($fieldid, $value) {
global $adb, $table_prefix;
static $fieldinfo = array();
if (!isset($fieldinfo[$fieldid])) {
$res = $adb->pquery(
"select
{$table_prefix}_tab.name as modulename,
fieldid, fieldname, tablename, columnname
from {$table_prefix}_field
inner join {$table_prefix}_tab on {$table_prefix}_tab.tabid = {$table_prefix}_field.tabid
where fieldid=? and {$table_prefix}_field.presence in (0,2)",
array($fieldid)
);
if ($res && $adb->num_rows($res) > 0) {
$fieldinfo[$fieldid] = $adb->FetchByAssoc($res, -1, false);
}
}
if (isset($fieldinfo[$fieldid])) {
$focus = CRMEntity::getInstance($fieldinfo[$fieldid]['modulename']);
if (empty($focus)) return null;
$indexname = $focus->tab_name_index[$fieldinfo[$fieldid]['tablename']];
if (empty($indexname)) return null;
$ret = array();
if ($fieldinfo[$fieldid]['tablename'] != $table_prefix.'_crmentity') {
$join = "inner join {$table_prefix}_crmentity on {$table_prefix}_crmentity.crmid = {$fieldinfo[$fieldid]['tablename']}.$indexname";
} else {
$join = "";
}
$res2 = $adb->pquery("select crmid from {$fieldinfo[$fieldid]['tablename']} $join where {$table_prefix}_crmentity.deleted = 0 and {$fieldinfo[$fieldid]['columnname']} = ?", array($value));
if ($res2 && $adb->num_rows($res2) > 0) {
while ($row2 = $adb->FetchByAssoc($res2, -1, false)) {
$ret[] = $row2['crmid'];
}
return $ret;
}
}
return null;
}
//crmv@34627e
//crmv@32334
function isZMergeAgent() {
if (function_exists('getallheaders')) {
$headers = getallheaders();
if (is_array($headers) && !empty($headers['User-Agent']) && stripos($headers['User-Agent'], 'zMerge') !== false) {
trackPlugin($headers['User-Agent']); //crmv@54179
return true;
}
}
return false;
}
//crmv@32334e
//crmv@48267
function isVteSyncAgent() {
if (function_exists('getallheaders')) {
$headers = getallheaders();
if (is_array($headers) && !empty($headers['User-Agent']) && stripos($headers['User-Agent'], 'VteSync') !== false) {
trackPlugin($headers['User-Agent']); //crmv@54179
return true;
}
}
return false;
}
//crmv@48267e
//crmv@37362
function setWinMaxStatus() {
global $current_user;
if ($current_user->column_fields['menu_view'] != '') {
if (isMobile()) {
$cookie_value = 'open';
} elseif ($current_user->column_fields['menu_view'] == 'Large Menu') {
$cookie_value = 'open';
} elseif ($current_user->column_fields['menu_view'] == 'Small Menu') {
$cookie_value = 'close';
}
} else {
$cookie_value = 'open';
}
$_COOKIE['crmvWinMaxStatus'] = $cookie_value;
}
//crmv@37362e
// crmv@39110
function requestFromMobile() {
return (preg_match('/^WSMobile.*/', VteSession::get('app_unique_key')) > 0);
}
// crmv@39110e
// crmv@142358 crmv@181168
function requestFromPortal() {
return (preg_match('/vteservice.php$/', $_SERVER['SCRIPT_NAME']) > 0);
}
// crmv@142358e crmv@181168e
// crmv@91082
function requestFromWebservice() {
return (preg_match('/webservice.php$/', $_SERVER['SCRIPT_NAME']) > 0);
}
// crmv@91082e
//crmv@49510
function getFinalTypeOfData($typeofdata, $mandatory) {
$tmp = explode('~',$typeofdata);
if ($tmp[1] != 'M' && $mandatory == '0') {
$tmp[1] = 'M';
$typeofdata = implode('~',$tmp);
}
return $typeofdata;
}
//crmv@49510e
//crmv@2043m crmv@56233
function checkMailScannerInfoRule($row) {
global $currentModule, $table_prefix;
//crmv@2043m crmv@OPER6053
if (in_array($row->linklabel,array('Rispondi via mail','Rispondi via mail (info)', 'Answer by mail', 'Answer by mail (info)'))) { // crmv@104782
$mailscanner = getSingleFieldValue($table_prefix.'_troubletickets', 'mailscanner_action', 'ticketid', $_REQUEST['record']);
if (!empty($mailscanner)) {
return true;
}
}
//crmv@2043me crmv@OPER6053e
if ($row->linktype == 'DETAILVIEWBASIC' && $row->linklabel == 'LBL_DO_NOT_IMPORT_ANYMORE') {
$linkurl = $row->linkurl;
$linkurl = str_replace(",'DetailView');",'',$linkurl);
$id = str_replace("doNotImportAnymore('HelpDesk',",'',$linkurl);
if (is_numeric($id)) {
$focus = CRMEntity::getInstance('HelpDesk');
$focus->retrieve_entity_info($id,'HelpDesk');
if (!empty($focus->column_fields['mailscanner_action']) && isPermitted($currentModule,'EditView',$id) && isPermitted($currentModule,'Delete',$id)) { //crmv@179057
return true;
}
}
} elseif ($row->linktype == 'LISTVIEWBASIC' && $row->linklabel == 'LBL_DO_NOT_IMPORT_ANYMORE') {
if (isPermitted($currentModule, 'EditView', '') == 'yes' && isPermitted($currentModule, 'Delete', '') == 'yes') { //crmv@179057
return true;
}
}
return false;
}
//crmv@2043me crmv@56233e
function preprint($arr,$die=false) {
echo '';
print_r($arr);
echo '
';
if ($die) die;
}
//crmv@54179
function getInstalledPlugins() {
$cache = Cache::getInstance('installed_plugins');
$installed_plugins = $cache->get();
if ($installed_plugins === false) {
global $adb, $table_prefix;
$installed_plugins = array();
$result = $adb->query("SELECT name, last_check FROM {$table_prefix}_plugins_tracking");
if ($result && $adb->num_rows($result) > 0) {
while($row=$adb->fetchByAssoc($result)) {
$installed_plugins[$row['name']] = $row['last_check'];
}
}
$cache->set($installed_plugins);
}
return $installed_plugins;
}
function trackPlugin($name) {
global $adb, $table_prefix;
$plugins = getInstalledPlugins();
if (!isset($plugins[$name])) {
$cache = Cache::getInstance('installed_plugins');
$cache->clear();
$adb->pquery("INSERT INTO {$table_prefix}_plugins_tracking (name,last_check) VALUES (?,?)",array($name,date('Y-m-d H:i:s')));
}
}
//crmv@54179e
/**
* truncateHtml can truncate a string up to a number of characters while preserving whole words and HTML tags
*
* @param string $text String to truncate.
* @param integer $length Length of returned string, including ellipsis.
* @param string $ending Ending to be appended to the trimmed string.
* @param boolean $considerHtml If true, HTML tags would be handled correctly
*
* @return string Trimmed string.
*/
/* crmv@59626 */
function truncateHtml($text, $length = 100, $ending = '...', $considerHtml = true) {
if ($considerHtml) {
// if the plain text is shorter than the maximum length, return the whole text
if (strlen(preg_replace('/<.*?>/', '', $text)) <= $length) {
return $text;
}
// splits all html-tags to scanable lines
preg_match_all('/(<.+?>)?([^<>]*)/s', $text, $lines, PREG_SET_ORDER);
$total_length = strlen($ending);
$open_tags = array();
$truncate = '';
foreach ($lines as $line_matchings) {
// if there is any html-tag in this line, handle it and add it (uncounted) to the output
if (!empty($line_matchings[1])) {
// if it's an "empty element" with or without xhtml-conform closing slash
if (preg_match('/^<(\s*.+?\/\s*|\s*(img|br|input|hr|area|base|basefont|col|frame|isindex|link|meta|param)(\s.+?)?)>$/is', $line_matchings[1])) {
// do nothing
// if tag is a closing tag
} else if (preg_match('/^<\s*\/([^\s]+?)\s*>$/s', $line_matchings[1], $tag_matchings)) {
// delete tag from $open_tags list
$pos = array_search($tag_matchings[1], $open_tags);
if ($pos !== false) {
unset($open_tags[$pos]);
}
// if tag is an opening tag
} else if (preg_match('/^<\s*([^\s>!]+).*?>$/s', $line_matchings[1], $tag_matchings)) {
// add tag to the beginning of $open_tags list
array_unshift($open_tags, strtolower($tag_matchings[1]));
}
// add html-tag to $truncate'd text
$truncate .= $line_matchings[1];
}
// clean html-tag at the end of the line
$line_matchings[2] = preg_replace('/(<(\s*[^>]+?\/\s*|\s*(img|br|input|hr|area|base|basefont|col|frame|isindex|link|meta|param)(\s[^>]+?)?)>)+$/is', '', $line_matchings[2]);
// calculate the length of the plain text part of the line; handle entities as one character
$content_length = strlen(preg_replace('/&[0-9a-z]{2,8};|[0-9]{1,7};|[0-9a-f]{1,6};/i', ' ', $line_matchings[2]));
if ($total_length+$content_length> $length) {
// the number of characters which are left
$left = $length - $total_length;
$entities_length = 0;
// search for html entities
if (preg_match_all('/&[0-9a-z]{2,8};|[0-9]{1,7};|[0-9a-f]{1,6};/i', $line_matchings[2], $entities, PREG_OFFSET_CAPTURE)) {
// calculate the real length of all entities in the legal range
foreach ($entities[0] as $entity) {
if ($entity[1]+1-$entities_length <= $left) {
$left--;
$entities_length += strlen($entity[0]);
} else {
// no more characters left
break;
}
}
}
$truncate .= substr($line_matchings[2], 0, $left+$entities_length);
$tmp = substr($line_matchings[2], 0, $left+$entities_length);
// maximum lenght is reached, so get off the loop
break;
} else {
$tmp = $line_matchings[2];
$truncate .= $line_matchings[2];
$total_length += $content_length;
}
// if the maximum length is reached, get off the loop
if($total_length >= $length) {
break;
}
}
} else {
if (strlen($text) <= $length) {
return $text;
} else {
$truncate = substr($text, 0, $length - strlen($ending));
}
}
// add the defined ending to the text
$truncate .= $ending;
if($considerHtml) {
// close all unclosed html-tags
foreach ($open_tags as $tag) {
$truncate .= '' . $tag . '>';
}
}
return $truncate;
}
//crmv@63483
function checkPermittedLink(&$instance) {
$module = vtlib_purify($_REQUEST['module']);
$record = vtlib_purify($_REQUEST['record']);
if (in_array($instance->linklabel,array('LBL_ADD_DOCREVISION'))) {
$permission = isPermitted($module,'EditView',$record);
if (empty($mailscanner) && $permission == 'no') {
return false;
}
}
return true;
}
//crmv@63483e
//crmv@102334
function oldModeSessionModules() {
// modules without tabs
return array('Calendar','Users');
}
function getLVS($module,$param='',$modhomeid='') {
$oldMode = oldModeSessionModules();
if (in_array($module,$oldMode)) {
if (empty($param)) {
return VteSession::getArray(array('lvs', $module));
} else {
return VteSession::getArray(array('lvs', $module, $param));
}
} else {
if (empty($modhomeid)) {
require_once('include/utils/ModuleHomeView.php');
global $current_user;
$MHW = ModuleHomeView::getInstance($module, $current_user->id);
$modhomeid = $MHW->getModHomeId(null, false); // crmv@123718
}
if (empty($param)) {
return VteSession::getArray(array('lvs', $module, $modhomeid));
} else {
return VteSession::getArray(array('lvs', $module, $modhomeid, $param));
}
}
}
function setLVS($module,$value,$param='',$modhomeid='') {
$oldMode = oldModeSessionModules();
if (in_array($module,$oldMode)) {
if (empty($param)) {
VteSession::setArray(array('lvs', $module), $value);
} else {
VteSession::setArray(array('lvs', $module, $param), $value);
}
} else {
if (empty($modhomeid)) {
require_once('include/utils/ModuleHomeView.php');
global $current_user;
$MHW = ModuleHomeView::getInstance($module, $current_user->id);
$modhomeid = $MHW->getModHomeId(null, false); // crmv@123718
}
if (empty($param)) {
VteSession::setArray(array('lvs', $module, $modhomeid), $value);
} else {
VteSession::setArray(array('lvs', $module, $modhomeid, $param), $value);
}
}
}
function unsetLVS($module='',$param='') {
if (!empty($param)) {
$oldMode = oldModeSessionModules();
if (in_array($module,$oldMode)) {
VteSession::setArray(array('lvs', $module, $param), '');
} else {
require_once('include/utils/ModuleHomeView.php');
global $current_user;
$MHW = ModuleHomeView::getInstance($module, $current_user->id);
$modhomeid = $MHW->getModHomeId(null, false); // crmv@123718
VteSession::setArray(array('lvs', $module, $modhomeid, $param), '');
}
} elseif (!empty($module))
VteSession::removeArray(array('lvs', $module));
else
VteSession::remove('lvs');
}
function getLVSDetails($module,$viewid,$param='') {
$oldMode = oldModeSessionModules();
if (in_array($module,$oldMode)) {
if (!empty($param)) {
return VteSession::getArray(array('lvs', $module, $viewid, $param));
} else {
return VteSession::getArray(array('lvs', $module, $viewid));
}
} else {
require_once('include/utils/ModuleHomeView.php');
global $current_user;
$MHW = ModuleHomeView::getInstance($module, $current_user->id);
$modhomeid = $MHW->getModHomeId(null, false); // crmv@123718
if (!empty($param)) {
return VteSession::getArray(array('lvs', $module, $modhomeid, $viewid, $param));
} else {
return VteSession::getArray(array('lvs', $module, $modhomeid, $viewid));
}
}
}
function setLVSDetails($module,$viewid,$value,$param='') {
$oldMode = oldModeSessionModules();
if (in_array($module,$oldMode)) {
if (!empty($param)) {
VteSession::setArray(array('lvs', $module, $viewid, $param), $value);
} else {
VteSession::setArray(array('lvs', $module, $viewid), $value);
}
} else {
require_once('include/utils/ModuleHomeView.php');
global $current_user;
$MHW = ModuleHomeView::getInstance($module, $current_user->id);
$modhomeid = $MHW->getModHomeId(null, false); // crmv@123718
if (!empty($param)) {
VteSession::setArray(array('lvs', $module, $modhomeid, $viewid, $param), $value);
} else {
VteSession::setArray(array('lvs', $module, $modhomeid, $viewid), $value);
}
}
}
//crmv@102334e
//crmv@104566
function getModuleImg($module, $style='') {
return '';
}
//crmv@104566e