* SPDX-License-Identifier: AGPL-3.0-only ************************************/ /* crmv@47905bis crmv@171009 */ include_once('modules/SDK/LangUtils.php'); include_once('modules/SDK/SDKUtils.php'); class SDK extends SDKUtils { protected static $sdk_session_keys = array('sdk_uitype', 'sdk_utils', 'sdk_popup_return_funct', 'sdk_smarty', 'sdk_presave', 'sdk_popup_query', 'sdk_adv_query', 'sdk_adv_permission', 'sdk_class_all', 'sdk_class', 'sdk_class_parent', 'sdk_view', 'sdk_file', 'sdk_home_iframe', 'sdk_reportfolders', 'sdk_reports', 'sdk_js_lang', 'sdk_transitions', 'vte_languages', 'sdk_pdf_cfunctions'); //crmv@2539m crmv@208472 protected static $other_session_keys = array('installed_modules'); public static $cacheFolder = 'cache/sys/SDK/'; /** * Invoked when special actions are performed on the module. * @param String Module name * @param String Event Type */ function vtlib_handler($moduleName, $eventType) { global $adb,$table_prefix; if($eventType == 'module.postinstall') { require_once('modules/SDK/InstallTables.php'); $adb->pquery('UPDATE '.$table_prefix.'_tab SET customized=0 WHERE name=?', array($moduleName)); $moduleInstance = Vtecrm_Module::getInstance('SDK'); Vtecrm_Link::addLink($moduleInstance->id,'HEADERSCRIPT','SDKScript','modules/SDK/SDK.js'); self::setUtil('modules/SDK/LangUtils.php'); self::setUtil('modules/SDK/src/Utils.php'); self::setUtil('modules/SDK/src/Favorites/Utils.php'); $langinfo = vtlib_getToggleLanguageInfo(); $languages = array_keys($langinfo); if (empty($languages)) { $languages = array('en_us','it_it'); } foreach ($languages as $language){ self::importPhpLanguage($language); //l'import della lingua js viene fatto in Header.tpl } $adb->pquery('DELETE FROM '.$table_prefix.'_profile2tab WHERE tabid = ?',array($moduleInstance->id)); $adb->pquery('DELETE FROM '.$table_prefix.'_profile2standardperm WHERE tabid = ?',array($moduleInstance->id)); $adb->pquery('DELETE FROM '.$table_prefix.'_profile2utility WHERE tabid = ?',array($moduleInstance->id)); $adb->pquery('DELETE FROM '.$table_prefix.'_profile2field WHERE tabid = ?',array($moduleInstance->id)); $moduleInstance->hide(array('hide_module_manager'=>1,'hide_profile'=>0,'hide_report'=>1)); self::setUitype('201','modules/SDK/src/201/201.php','modules/SDK/src/201/201.tpl','modules/SDK/src/201/201.js'); //crmv@26523 self::setUitype('202','modules/SDK/src/202/202.php','modules/SDK/src/202/202.tpl','modules/SDK/src/202/202.js'); //crmv@26809 self::setUitype('203','modules/SDK/src/203/203.php','modules/SDK/src/203/203.tpl','modules/SDK/src/203/203.js'); //crmv@26809 self::setMenuButton('fixed','LBL_FAVORITES',"showFloatingDiv('favorites',this);getFavoriteList();",'grade'); //crmv@26986 //crmv@56233 SDK::setUitype(204,'modules/SDK/src/204/204.php','modules/SDK/src/204/204.tpl',''); $moduleInstance = Vtecrm_Module::getInstance('HelpDesk'); Vtecrm_Link::addLink($moduleInstance->id, 'DETAILVIEWBASIC', 'LBL_DO_NOT_IMPORT_ANYMORE', "javascript:doNotImportAnymore('\$MODULE\$',\$RECORD\$,'DetailView');", 'vteicon:whatshot',0,'checkMailScannerInfoRule:include/utils/crmv_utils.php'); Vtecrm_Link::addLink($moduleInstance->id, 'LISTVIEWBASIC', 'LBL_DO_NOT_IMPORT_ANYMORE', "javascript:doNotImportAnymore('\$MODULE\$','','MassListView');",'',0,'checkMailScannerInfoRule:include/utils/crmv_utils.php'); //crmv@56233e //crmv@29079 self::setUitype(205,'modules/SDK/src/205/205.php','modules/SDK/src/205/205.tpl',''); //crmv@30014 self::setUitype(206, 'modules/SDK/src/206/206.php', 'modules/SDK/src/206/206.tpl', 'modules/SDK/src/206/206.js', 'integer'); if (Vtecrm_Utils::CheckTable($table_prefix.'_home_iframe')) { $adb->pquery('insert into '.$table_prefix.'_home_iframe (hometype,url) values (?,?)',array('MODCOMMENTS','index.php?module=ModComments&action=ModCommentsAjax&file=ModCommentsWidgetHandler&ajax=true&widget=DetailViewBlockCommentWidget')); } $homeModule = Vtecrm_Module::getInstance('SDK'); $homeModule->addLink('HEADERSCRIPT', 'NotificationsScript', 'modules/SDK/src/Notifications/NotificationsCommon.js'); $homeModule->addLink('HEADERCSS', 'NotificationsScript', 'modules/SDK/src/Notifications/NotificationsCommon.css'); //crmv@29079e self::addView('Users', 'modules/SDK/src/modules/Users/UsersView.php', 'constrain', 'continue'); //crmv@29506 $result = $adb->pquery("select * from {$table_prefix}_field where tabid = 13 and fieldname in (?,?)",array('projecttaskid','projectplanid')); if ($result && $adb->num_rows($result) == 2) { self::setPopupQuery('field', 'HelpDesk', 'projecttaskid', 'modules/SDK/src/modules/HelpDesk/ProjectTaskQuery.php', array('projectplanid'=>'getObj("projectplanid").value')); } SDK::setUitype(207,'modules/SDK/src/207/207.php','modules/SDK/src/207/207.tpl','modules/SDK/src/207/207.js'); //crmv@2539m SDK::setPDFCustomFunction('if-else','its4you_if',array('param1','comparator','param2','return1','return2')); SDK::setPDFCustomFunction('Contact Image','its4you_getContactImage',array('contactid','width','height')); SDK::setPDFCustomFunction('Net Prices Total','getTotalNetPrice',array('$CRMID$')); SDK::setPDFCustomFunction('Discount Prices Total','getTotalDiscountPrice','$CRMID$'); //crmv@2539me SDK::setUitype(210, 'modules/SDK/src/210/210.php', 'modules/SDK/src/210/210.tpl', 'modules/SDK/src/210/210.js', 'text'); // crmv@95157 SDK::setUitype(212, 'modules/SDK/src/212/212.php', 'modules/SDK/src/212/212.tpl', 'modules/SDK/src/212/212.js', 'picklist'); require_once('modules/Documents/storage/StorageBackendUtils.php'); $SBU = StorageBackendUtils::getInstance(); $SBU->syncDB(); // crmv@95157e SDK::setUitype(213, 'modules/SDK/src/213/213.php', 'modules/SDK/src/213/213.tpl', ''); SDK::setUitype(214, 'modules/SDK/src/214/214.php', 'modules/SDK/src/214/214.tpl', '', 'datetime'); // crmv@101930 SDK::setUitype(215,'modules/SDK/src/215/215.php','modules/SDK/src/215/215.tpl','modules/SDK/src/215/215.js'); // crmv@150808 SDK::setUitype(220, 'modules/SDK/src/220/220.php', 'modules/SDK/src/220/220.tpl', 'modules/SDK/src/220/220.js', 'table'); // crmv@102879 SDK::setUitype(221, 'modules/SDK/src/221/221.php', 'modules/SDK/src/221/221.tpl', 'modules/SDK/src/221/221.js', 'string'); //crmv@174986 // crmv@201442 SDK::setUitype(310, 'modules/SDK/src/310/310.php','modules/SDK/src/310/310.tpl', '', 'picklist'); SDK::setUitype(311, 'modules/SDK/src/311/311.php','modules/SDK/src/311/311.tpl', '', 'multipicklist'); // crmv@201442e // migrate old reference uitypes to uitype 10 - i $acc = 'modules/SDK/src/ReturnFunct/ReturnAccountAddress.php'; $cont = 'modules/SDK/src/ReturnFunct/ReturnContactAddress.php'; $pot = 'modules/SDK/src/ReturnFunct/ReturnPotentialAddress.php'; $prod = 'modules/SDK/src/ReturnFunct/ReturnProductLines.php'; $vend = 'modules/SDK/src/ReturnFunct/ReturnVendorAddress.php'; $user = 'modules/SDK/src/ReturnFunct/ReturnUserLastname.php'; SDK::setPopupReturnFunction('Accounts', 'account_id', $acc); SDK::setPopupReturnFunction('Contacts', 'account_id', $acc); SDK::setPopupReturnFunction('Contacts', 'contact_id', $cont); SDK::setPopupReturnFunction('Calendar', 'contact_id', $cont); SDK::setPopupReturnFunction('Events', 'contact_id', $cont); SDK::setPopupReturnFunction('Quotes', 'contact_id', $cont); SDK::setPopupReturnFunction('PurchaseOrder', 'contact_id', $cont); SDK::setPopupReturnFunction('SalesOrder', 'contact_id', $cont); SDK::setPopupReturnFunction('Invoice', 'contact_id', $cont); SDK::setPopupReturnFunction('Quotes', 'account_id', $acc); SDK::setPopupReturnFunction('SalesOrder', 'account_id', $acc); SDK::setPopupReturnFunction('Invoice', 'account_id', $acc); SDK::setPopupReturnFunction('Quotes', 'potential_id', $pot); SDK::setPopupReturnFunction('SalesOrder', 'potential_id', $pot); SDK::setPopupReturnFunction('SalesOrder', 'quote_id', $prod); SDK::setPopupReturnFunction('Invoice', 'salesorder_id', $prod); SDK::setPopupReturnFunction('PurchaseOrder', 'vendor_id', $vend); SDK::setPopupReturnFunction('Users', 'reports_to_id', $user); SDK::setPopupReturnFunction('Timecards', 'newresp', $user); SDK::setPopupReturnFunction('Projects', 'reports_to_id', $user); $popup_query_file = 'modules/SDK/src/PopupQuery/ExcludeCurrentUser.php'; SDK::setPopupQuery('field', 'Users', 'reports_to_id', $popup_query_file); SDK::setPopupQuery('field', 'Timecards', 'newresp', $popup_query_file); SDK::setPopupQuery('field', 'Projects', 'reports_to_id', $popup_query_file); // migrate old reference uitypes to uitype 10 - e //crmv@3078m $result = $adb->query("SELECT * FROM sdk_menu_fixed WHERE title = 'Events'"); if ($result) { if ($adb->num_rows($result)>0){ $adb->query("delete FROM sdk_menu_fixed WHERE title = 'Events'"); } SDK::setMenuButton('fixed','Events',"showFloatingDiv('events',this);getEventList(this);",'event'); } $homeModule->addLink('HEADERSCRIPT','EventUtils','modules/SDK/src/Events/js/Utils.js'); //crmv@3078me // crmv@44323 - sharkpanel report :( SDK::setReportFolder('Budget', ''); SDK::setReport('Budget by Product Line', '', 'Budget', 'modules/Potentials/BudgetReportRun.php', 'BudgetReportRun', 'budgetParams'); $result = $adb->pquery("SELECT {$table_prefix}_report.reportid, {$table_prefix}_report.folderid FROM sdk_reports INNER JOIN {$table_prefix}_report ON sdk_reports.reportid = {$table_prefix}_report.reportid WHERE runclass = ?", array('BudgetReportRun')); if ($result && $adb->num_rows($result) > 0) { $sharkReportId = $adb->query_result($result,0,'reportid'); $sharkReportFolder = $adb->query_result($result,0,'folderid'); SDK::setMenuButton('contestual', 'Budget', "window.location='index.php?module=Reports&action=SaveAndRun&record={$sharkReportId}&folderid={$sharkReportFolder}';", 'euro_symbol', 'Potentials', 'index'); } // crmv@44323e //crmv@52306 crmv@54900 $result = $adb->pquery("SELECT relation_id, name FROM {$table_prefix}_relatedlists WHERE tabid = 14 AND related_tabid = 14 AND label = ?",array('Product Bundles')); if ($result && $adb->num_rows($result) > 0) { $relation_id = $adb->query_result($result,0,'relation_id'); $method = $adb->query_result($result,0,'name'); SDK::setTurboliftCount($relation_id, $method); } $result = $adb->query("SELECT relation_id, name FROM {$table_prefix}_relatedlists WHERE tabid = 14 AND related_tabid = 14 AND label LIKE 'Parent Product%'"); if ($result && $adb->num_rows($result) > 0) { $relation_id = $adb->query_result($result,0,'relation_id'); $method = $adb->query_result($result,0,'name'); SDK::setTurboliftCount($relation_id, $method); } $result = $adb->query("SELECT relation_id, name FROM {$table_prefix}_relatedlists WHERE tabid = 7 AND related_tabid = 26"); if ($result && $adb->num_rows($result) > 0) { $relation_id = $adb->query_result($result,0,'relation_id'); $method = $adb->query_result($result,0,'name'); SDK::setTurboliftCount($relation_id, $method); } //crmv@52306e crmv@54900e // crmv@142678 $campInst = Vtecrm_Module::getInstance('Campaigns'); $result = $adb->pquery("SELECT relation_id, name FROM {$table_prefix}_relatedlists WHERE tabid = ? AND related_tabid = ? AND name LIKE 'get_statistics_%'", array($campInst->id, 0)); if ($result) { while ($row = $adb->fetchByAssoc($result, -1, false)) { SDK::setTurboliftCount($row['relation_id'], $row['name']); } } // crmv@142678e //crmv@62414 $documents_instance = Vtecrm_Module::getInstance('Documents'); Vtecrm_Link::addLink($documents_instance->id, 'DETAILVIEWWIDGET', 'DOC_PREVIEW', "module=Documents&action=DocumentsAjax&file=PreviewFile&mode=button&record=$"."RECORD$"); //crmv@62414e //crmv@64516 $configPBFile = 'modules/Campaigns/ProcessBounces.config.php'; if (!file_exists($configPBFile)) { $configPBTemplate = file_get_contents('modules/Campaigns/ProcessBounces.config.template.php'); file_put_contents($configPBFile, $configPBTemplate); } //crmv@64516e //crmv@OPER5904 $moduleInstance = Vtecrm_Module::getInstance('SDK'); Vtecrm_Link::addLink($moduleInstance->id,'HEADERSCRIPT','VTELocalStorageScript','modules/SDK/src/VTELocalStorage.js'); //crmv@OPER5904e // crmv@OPER6317 Vtecrm_Link::addLink($moduleInstance->id, 'HEADERSCRIPT', 'Wizard', 'include/js/Wizard.js'); // crmv@OPER6317e /* TODO@bosch SDK::setUitype(213, 'modules/SDK/src/213/213.php', 'modules/SDK/src/213/213.tpl', ''); */ SDK::setUitype(49,'modules/SDK/src/49/49.php','modules/SDK/src/49/49.tpl','modules/SDK/src/49/49.js'); // crmv@187823 //crmv@101683 $uitype = 51; SDK::setUitype($uitype,"modules/SDK/src/$uitype/$uitype.php","modules/SDK/src/$uitype/$uitype.tpl","modules/SDK/src/$uitype/$uitype.js",'reference'); $result = $adb->pquery("select fieldtypeid from {$table_prefix}_ws_fieldtype where uitype=?", array($uitype)); if ($result && $adb->num_rows($result) > 0) { $check = $adb->pquery("select fieldtypeid from {$table_prefix}_ws_referencetype where fieldtypeid=?", array($adb->query_result($result,0,'fieldtypeid'))); if ($check && $adb->num_rows($check) == 0) { if ($adb->isMysql()) { $adb->pquery("insert ignore into {$table_prefix}_ws_referencetype(fieldtypeid,type) values(?,?)",array($adb->query_result($result,0,'fieldtypeid'),'Users')); } else { $adb->pquery("insert into {$table_prefix}_ws_referencetype(fieldtypeid,type) values(?,?)",array($adb->query_result($result,0,'fieldtypeid'),'Users')); } } } $uitype = 50; SDK::setUitype($uitype,"modules/SDK/src/$uitype/$uitype.php","modules/SDK/src/$uitype/$uitype.tpl","modules/SDK/src/$uitype/$uitype.js",'reference'); $result = $adb->pquery("select fieldtypeid from {$table_prefix}_ws_fieldtype where uitype=?", array($uitype)); if ($result && $adb->num_rows($result) > 0) { $check = $adb->pquery("select fieldtypeid from {$table_prefix}_ws_referencetype where fieldtypeid=?", array($adb->query_result($result,0,'fieldtypeid'))); if ($check && $adb->num_rows($check) == 0) { if ($adb->isMysql()) { $adb->pquery("insert ignore into {$table_prefix}_ws_referencetype(fieldtypeid,type) values(?,?)",array($adb->query_result($result,0,'fieldtypeid'),'Users')); } else { $adb->pquery("insert into {$table_prefix}_ws_referencetype(fieldtypeid,type) values(?,?)",array($adb->query_result($result,0,'fieldtypeid'),'Users')); } } } //crmv@101683e SDK::setProcessMakerFieldAction('vte_sum','modules/SDK/src/ProcessMaker/Utils.php','Sum (number1,number2,...)'); SDK::setProcessMakerFieldAction("date_now", "modules/SDK/src/ProcessMaker/Utils.php", "Now Date (format)", '', 'LBL_PM_SDK_DATE_FUNCTIONS'); SDK::setProcessMakerFieldAction("formatDate", "modules/SDK/src/ProcessMaker/Utils.php", "Format Date/Time (date, format)", '', 'LBL_PM_SDK_DATE_FUNCTIONS'); SDK::setProcessMakerFieldAction("diffDate", "modules/SDK/src/ProcessMaker/Utils.php", "DiffDays (date1, date2)", '', 'LBL_PM_SDK_DATE_FUNCTIONS'); SDK::setProcessMakerTaskCondition('get_running_process_current_user', 'modules/SDK/src/ProcessMaker/Utils.php', 'LBL_RUNNING_PROCESS_CURRENT_USER'); $homeModule->addLink('HEADERSCRIPT', 'HistoryScript', 'include/js/HistoryTab.js'); //crmv@104566 SDK::setUitype(1016, 'modules/SDK/src/1016/1016.php', 'modules/SDK/src/1016/1016.tpl', 'modules/SDK/src/1016/1016.js', 'signature'); // crmv@104567 SDK::setUitype(29,'modules/SDK/src/29/29.php','modules/SDK/src/29/29.tpl','','file'); //crmv@115268 SDK::setUitype(73, 'modules/SDK/src/73/73.php', 'modules/SDK/src/73/73.tpl', '', 'time'); //crmv@128159 SDK::addView('Events', 'modules/SDK/src/modules/Calendar/EventsView.php', 'constrain', 'continue'); //crmv@158871 SDK::setUitype(209,'modules/SDK/src/209/209.php','modules/SDK/src/209/209.tpl','','url'); SDK::setUitype(86,'modules/SDK/src/86/86.php','modules/SDK/src/86/86.tpl','modules/SDK/src/86/86.js','whatsapp'); //crmv@174813 $uitype = 54; $result = $adb->pquery("select fieldtypeid from {$table_prefix}_ws_fieldtype where uitype=?", array($uitype)); if ($result && $adb->num_rows($result) == 0) { $fieldtypeid = $adb->getUniqueID($table_prefix."_ws_fieldtype"); $adb->pquery("insert into {$table_prefix}_ws_fieldtype(fieldtypeid,uitype,fieldtype) values(?,?,?)",array($fieldtypeid,$uitype,'reference')); $adb->pquery("insert into {$table_prefix}_ws_referencetype(fieldtypeid,type) values(?,?)",array($fieldtypeid,'Groups')); } //crmv@174813e } else if($event_type == 'module.disabled') { // TODO Handle actions when this module is disabled. } else if($event_type == 'module.enabled') { // TODO Handle actions when this module is enabled. } else if($eventType == 'module.preuninstall') { // TODO Handle actions when this module is about to be deleted. } else if($eventType == 'module.preupdate') { // TODO Handle actions before this module is updated. } else if($eventType == 'module.postupdate') { // TODO Handle actions after this module is updated. } } static function log($message, $delimit=true) { Vtecrm_Utils::Log($message, $delimit); } static function getSessionKeys($add_other_session_keys=false) { return SDK::$sdk_session_keys; } static function clearSessionValue($key) { global $table_prefix; $dependentSessions = array( 'sdk_uitype' => array('sdk_js_uitype'), 'sdk_home_iframe' => array('sdk_home_global_iframe','sdk_home_default_iframes_plain','sdk_home_default_iframes_complex','sdk_home_global_iframes','sdk_home_fixed_iframes'), 'sdk_home_global_iframe' => array('sdk_home_iframe','sdk_home_default_iframes_plain','sdk_home_default_iframes_complex','sdk_home_global_iframes','sdk_home_fixed_iframes'), 'sdk_home_default_iframes_plain' => array('sdk_home_iframe','sdk_home_global_iframe','sdk_home_default_iframes_complex','sdk_home_global_iframes','sdk_home_fixed_iframes'), 'sdk_home_default_iframes_complex' => array('sdk_home_iframe','sdk_home_global_iframe','sdk_home_default_iframes_plain','sdk_home_global_iframes','sdk_home_fixed_iframes'), 'sdk_home_global_iframes' => array('sdk_home_iframe','sdk_home_global_iframe','sdk_home_default_iframes_plain','sdk_home_default_iframes_complex','sdk_home_fixed_iframes'), 'sdk_home_fixed_iframes' => array('sdk_home_iframe','sdk_home_global_iframe','sdk_home_default_iframes_plain','sdk_home_default_iframes_complex','sdk_home_global_iframes'), ); $cache = Cache::getInstance($key,null,self::getCacheFolder()); $cache->clear(); if (in_array($key,array_keys($dependentSessions)) && !empty($dependentSessions[$key])) { foreach($dependentSessions[$key] as $dependentSession) { $cache = Cache::getInstance($dependentSession,null,self::getCacheFolder()); $cache->clear(); } } } static function clearSessionValues() { $keys = self::getSessionKeys(true); foreach ($keys as $k) { self::clearSessionValue($k); } foreach (SDK::$other_session_keys as $other_session_key) { $cache = Cache::getInstance($other_session_key); $cache->clear(); } } /** * Updates (or create a new one if it doesn't exist) an entry in the language table */ static function setLanguageEntry($module, $langid, $label, $newlabel) { global $adb; $languages = vtlib_getToggleLanguageInfo(); if (!array_key_exists($langid,$languages)) { self::log("Adding SDK Language Entry ($module $langid $label) ... FAILED: language $langid not installed"); return; } // delete old row self::deleteLanguageEntry($module, $langid, $label); // insert new $newid = $adb->getUniqueID("sdk_language"); $qparam = array($newid, $module, $langid, correctEncoding(html_entity_decode($label)), correctEncoding(html_entity_decode($newlabel))); $query = 'insert into sdk_language (languageid, module, language, label, trans_label) values ('.generateQuestionMarks($qparam).')'; $res = $adb->pquery($query, $qparam); self::log("Adding SDK Language Entry ($module $langid $label) ... DONE"); if ($module == 'ALERT_ARR') { self::clearSessionValue('sdk_js_lang'); } else { self::clearSessionValue("SDK/vte_languages/{$module}-{$langid}"); // crmv@187020 } } /** * Same as previous, but accepts multiple languages */ static function setLanguageEntries($module, $label, $strings) { foreach ($strings as $langid=>$newlabel) { self::setLanguageEntry($module, $langid, $label, $newlabel); } } /** * Deletes a string in the language table */ static function deleteLanguageEntry($module, $langid = NULL, $label = NULL) { global $adb; $query = 'delete from sdk_language where module = ?'; $qpar = array($module); if (!empty($langid)) { $query .= ' and language = ?'; $qpar[] = $langid; } if (!empty($label)) { ($adb->isMysql()) ? $query .= ' and binary label like ?' : $query .= ' and label like ?'; $qpar[] = $label; } $res = $adb->pquery($query, $qpar); if ($res && $adb->getAffectedRowCount($res) > 0) { self::log("Deleting SDK Language Entry ($module $langid) ... DONE"); } else { //self::log("Deleting SDK Language Entry ($module $langid) ... FAILED"); } if ($module == 'ALERT_ARR') { self::clearSessionValue('sdk_js_lang'); } else { self::clearSessionValue("SDK/vte_languages/{$module}-{$langid}"); // crmv@187020 } } static function getUitypes() { global $adb; $cache = Cache::getInstance('sdk_uitype',null,self::getCacheFolder()); $tmp = $cache->get(); if ($tmp === false) { $tmp = array(); $result = $adb->query('select * from sdk_uitype'); if ($result && $adb->num_rows($result)>0) { while($row=$adb->fetchByAssoc($result)) { $tmp[$row['uitype']] = $row; } } $cache->set($tmp); } return $tmp; } static function isUitype($uitype) { $uitypes = self::getUitypes(); if (in_array($uitype,array_keys($uitypes))) { return true; } return false; } static function isOldUitype($uitype) { $uitypes = self::getUitypes(); if (!empty($uitypes[$uitype]['old_style'])) { return true; } return false; } static function getUitypeInfo($uitype) { $uitypes = self::getUitypes(); return $uitypes[$uitype]; } static function getUitypeFile($src,$mode,$uitype) { global $sdk_mode; $sdk_mode = $mode; $info = self::getUitypeInfo($uitype); $checkFileAccess = $info['src_'.$src]; if ($src == 'tpl') { $checkFileAccess = "Smarty/templates/$checkFileAccess"; } if ($info['src_'.$src] != '' && Vtecrm_Utils::checkFileAccess($checkFileAccess,false)) { return $info['src_'.$src]; } } static function getJsUitypes() { global $adb; $cache = Cache::getInstance('sdk_js_uitype',null,self::getCacheFolder()); $tmp = $cache->get(); if ($tmp === false) { $tmp = array(); $result = $adb->query("SELECT uitype,src_js FROM sdk_uitype WHERE src_js <> '' OR src_js IS NOT NULL"); if ($result && $adb->num_rows($result)>0) { while($row=$adb->fetchByAssoc($result)) { $tmp[$row['uitype']] = $row['src_js']; } } $tmp = Zend_Json::encode($tmp); $cache->set($tmp); } return $tmp; } /** * Register new Uitype * $uitype : numeric value * $src_php : path of the php file source code * $src_tpl : path of the tpl file source code * $src_js : path of the js file source code * $type : webservice format (ex. text, boolean, datetime, reference, ...) * $params : array width other params (ex. modules per reference field) */ static function setUitype($uitype,$src_php,$src_tpl,$src_js,$type='',$params='') { global $adb,$table_prefix; $result = $adb->query('select * from sdk_uitype where uitype = '.$uitype); if ($result && $adb->num_rows($result)>0) { self::log("Adding SDK Uitype ($uitype) ... FAILED ($uitype already exists!)"); return; } $uitypeid = $adb->getUniqueID("sdk_uitype"); $params = array($uitypeid,$uitype,$src_php,$src_tpl,$src_js); $adb->pquery('insert into sdk_uitype (uitypeid,uitype,src_php,src_tpl,src_js) values ('.generateQuestionMarks($params).')',array($params)); if ($type != '') { $fieldtypeid = $adb->getUniqueId($table_prefix.'_ws_fieldtype'); $result = $adb->pquery("insert into ".$table_prefix."_ws_fieldtype(fieldtypeid,uitype,fieldtype) values(?,?,?)",array($fieldtypeid,$uitype,$type)); if ($type == 'reference') { //TODO : insert into vte_ws_referencetype self::log("TODO : insert into vte_ws_referencetype"); } } self::log("Adding SDK Uitype ($uitype) ... DONE"); // put it in the current session self::clearSessionValue('sdk_uitype'); //TODO@old_style $columns = array_keys($adb->datadict->MetaColumns('sdk_uitype')); if (in_array(strtoupper('old_style'),$columns) && in_array($uitype,array(170,171,172,173,174,175,176,177,206,1115))) { // crmv@70304 crmv@80653 $adb->pquery('update sdk_uitype set old_style = 1 where uitypeid = ?',array($uitypeid)); } } /** * Unregister a uitype * $uitype : the uitype to be unregistered. its files won't be deleted * TODO: cancellare da tabelle vte_ws* */ static function unsetUitype($uitype) { global $adb,$table_prefix; $res = $adb->pquery('delete from sdk_uitype where uitype = ?',array($uitype)); if ($res && $adb->getAffectedRowCount($res) > 0) { $adb->pquery('delete from '.$table_prefix.'_ws_fieldtype where uitype = ?',array($uitype)); self::log("Deleting SDK Uitype ($uitype) ... DONE"); self::clearSessionValue('sdk_uitype'); } else { self::log("Deleting SDK Uitype ($uitype) ... FAILED"); } } static function getUtilsList() { global $adb; if (empty($adb->database) || !$adb->table_exist('sdk_utils') || !isModuleInstalled('SDK')) { return; } $cache = Cache::getInstance('sdk_utils',null,self::getCacheFolder()); $tmp = $cache->get(); if ($tmp === false) { $tmp = array(); $result = $adb->query('select * from sdk_utils'); if ($result && $adb->num_rows($result)>0) { while($row=$adb->fetchByAssoc($result)) { $tmp[$row['utilid']] = $row['src']; } } $cache->set($tmp); } return $tmp; } static function getUtils() { $sdk_utils = self::getUtilsList(); if (!empty($sdk_utils)) { foreach ($sdk_utils as $sdk_util) { if ($sdk_util != '' && Vtecrm_Utils::checkFileAccess($sdk_util,false)) { require_once($sdk_util); } } } } /** * Register new Util * $src : path of the php file source code * Note: there is no control if the same file is included twice */ static function setUtil($src) { global $adb; if ($src == '') { self::log("Adding SDK Util ($src) ... FAILED (src empty!)"); return; } // check if it already exists $utils = self::getUtilsList(); if (!empty($utils) && in_array($src, array_values($utils))) { self::log("Adding SDK Util ($src) ... FAILED (File already in utils list)"); return; } $utilid = $adb->getUniqueID("sdk_utils"); $params = array($utilid,$src); $adb->pquery('insert into sdk_utils (utilid,src) values ('.generateQuestionMarks($params).')',array($params)); self::log("Adding SDK Util ($src) ... DONE"); self::clearSessionValue('sdk_utils'); } /** * Delete a registered util * $src: path to the php file to be unregistered (the file itself won't be deleted) */ static function unsetUtil($src) { global $adb; $res = $adb->pquery('delete from sdk_utils where src = ?',array($src)); if ($res && $adb->getAffectedRowCount($res) > 0) { self::log("Deleting SDK Util ($src) ... DONE"); self::clearSessionValue('sdk_utils'); } else { self::log("Deleting SDK Util ($src) ... FAILED"); } } static function getPopupReturnFunctions() { global $adb; $cache = Cache::getInstance('sdk_popup_return_funct',null,self::getCacheFolder()); $tmp = $cache->get(); if ($tmp === false) { $tmp = array(); $result = $adb->query('select * from sdk_popup_return_funct'); if ($result && $adb->num_rows($result)>0) { while($row=$adb->fetchByAssoc($result)) { $tmp[$row['id']] = array('module'=>$row['module'],'fieldname'=>$row['fieldname'],'src'=>$row['src']); } } $cache->set($tmp); } return $tmp; } static function isPopupReturnFunction($module,$fieldname) { if ($module != '' && $fieldname != '') { $popupReturnFunctions = self::getPopupReturnFunctions(); foreach($popupReturnFunctions as $id => $info) { if ($module == $info['module'] && $fieldname == $info['fieldname']) { return true; } } //crmv@131239 check for table fields if (substr_count($fieldname,'_') == 2) { list($t,$f,$o) = explode('_',$fieldname); return self::isPopupReturnFunction($module,"{$t}_{$f}"); } //crmv@131239e } return false; } static function getPopupReturnFunctionFile($module,$fieldname) { $popupReturnFunctions = self::getPopupReturnFunctions(); foreach($popupReturnFunctions as $id => $info) { if ($module == $info['module'] && $fieldname == $info['fieldname']) { return $info['src']; } } //crmv@131239 check for table fields if (substr_count($fieldname,'_') == 2) { list($t,$f,$o) = explode('_',$fieldname); return self::getPopupReturnFunctionFile($module,"{$t}_{$f}"); } //crmv@131239e } static function setPopupReturnFunction($module,$fieldname,$src) { global $adb; if ($module == '' || $fieldname == '' || $src == '') { self::log("Adding SDK Popup Return Function ($module,$fieldname,$src) ... FAILED (empty value)"); return; } // check duplicates $file = self::getPopupReturnFunctionFile($module, $fieldname); if (isset($file) && !empty($file)) { self::log("Adding SDK Popup Return Function ($src) ... FAILED (duplicate)"); return; } $id = $adb->getUniqueID("sdk_popup_return_funct"); $params = array($id,$module,$fieldname,$src); $adb->pquery('insert into sdk_popup_return_funct (id,module,fieldname,src) values ('.generateQuestionMarks($params).')',array($params)); self::log("Adding SDK Popup Return Function ($module,$fieldname,$src) ... DONE"); self::clearSessionValue('sdk_popup_return_funct'); } static function unsetPopupReturnFunction($module, $fieldname = NULL, $src = NULL) { global $adb; $query = 'delete from sdk_popup_return_funct where module = ?'; $qpar = array($module); if (!empty($fieldname)) { $query .= 'and fieldname = ?'; $qpar[] = $fieldname; } if (!empty($src)) { $query .= 'and src = ?'; $qpar[] = $src; } $res = $adb->pquery($query, $qpar); if ($res && $adb->getAffectedRowCount($res) > 0) { self::log("Deleting SDK Popup Return Function ($src) ... DONE"); self::clearSessionValue('sdk_popup_return_funct'); } else { self::log("Deleting SDK Popup Return Function ($src) ... FAILED"); } } static function getSmartyTemplates() { global $adb; $cache = Cache::getInstance('sdk_smarty',null,self::getCacheFolder()); $tmp = $cache->get(); if ($tmp === false) { $tmp = array(); $result = $adb->query('select * from sdk_smarty'); if ($result && $adb->num_rows($result)>0) { while($row=$adb->fetchByAssoc($result,-1,false)) { $tmp[$row['smartyid']] = array('params'=>$row['params'],'src'=>$row['src']); } } $cache->set($tmp); } return $tmp; } static function getSmartyTemplate($request) { $smartyTemplates = self::getSmartyTemplates(); $src = array(); foreach($smartyTemplates as $smartyTemplate) { $params = Zend_Json::decode($smartyTemplate['params']); // controllo se la request matcha con i parametri require_once('SDKParams.php'); if (SDKParams::paramsMatch($request, $params)) { $src[] = array($smartyTemplate['src'], $params); } } // choose best option (most specific/minimum) if (!empty($src)) { return SDKParams::paramsMin($src); } return ''; } /** * Register a custom template * Check if the new template params are compatible with the existing ones */ static function setSmartyTemplate($params,$src) { global $adb; // check parameters require_once('SDKParams.php'); $plist = self::getSmartyTemplates(); foreach ($plist as $k=>$t) $plist[$k] = Zend_Json::decode($t['params']); $compcheck = SDKParams::paramsValidate($plist, $params); if (!empty($compcheck)) { self::log("Adding SDK Smarty Template ($src) ... FAIL"); $failstr = ''; foreach ($compcheck as $v) { $failstr .= ($v[0]==1)?'Duplicated ':'Incompatible '; $failstr .= "params $v[1]\n"; } self::log(nl2br($failstr)); return; } $smartyid = $adb->getUniqueID("sdk_smarty"); $params = array($smartyid,Zend_Json::encode($params),$src); $adb->pquery('insert into sdk_smarty (smartyid,params,src) values ('.generateQuestionMarks($params).')',array($params)); self::log("Adding SDK Smarty Template ($src) ... DONE"); self::clearSessionValue('sdk_smarty'); } /** * Delete a registered template */ static function unsetSmartyTemplate($params, $src = NULL) { global $adb; $query = 'delete from sdk_smarty where params = ?'; $qpar = array(Zend_Json::encode($params)); if (!empty($src)) { $query .= 'and src = ?'; $qpar[] = $src; } $res = $adb->pquery($query, $qpar); if ($res && $adb->getAffectedRowCount($res) > 0) { self::log("Deleting SDK Smarty Template ($src) ... DONE"); self::clearSessionValue('sdk_smarty'); } else { self::log("Deleting SDK Smarty Template ($src) ... FAILED"); } } static function getNotRewritableSmartyTemplates() { $return = array( 'Header.tpl', 'modules/ModComments/widgets/DetailViewBlockComment.tpl', 'Buttons_List.tpl', 'Buttons_List1.tpl', 'Buttons_List4.tpl', 'Buttons_List_Detail.tpl', 'Buttons_List_Edit.tpl', 'loginheader.tpl', ); return $return; } static function setPreSave($module, $src) { global $adb; // check if module already has a presave file $presave = self::getPreSave($module); if (isset($presave) && !empty($presave)) { self::log("Adding SDK PreSave ($module) ... FAILED (PreSave already defined)"); return; } $presaveid = $adb->getUniqueID("sdk_presave"); $params = array($presaveid,$module,$src); $adb->pquery('insert into sdk_presave (presaveid,module,src) values ('.generateQuestionMarks($params).')',array($params)); self::log("Adding SDK PreSave ($src) ... DONE"); self::clearSessionValue('sdk_presave'); } static function unsetPreSave($module, $src = NULL) { global $adb; $query = 'delete from sdk_presave where module = ?'; $qpar = array($module); if (!empty($src)) { $query .= 'and src = ?'; $qpar[] = $src; } $res = $adb->pquery($query, $qpar); if ($res && $adb->getAffectedRowCount($res) > 0) { self::log("Deleting SDK PreSave ($src) ... DONE"); self::clearSessionValue('sdk_presave'); } else { self::log("Deleting SDK PreSave ($src) ... FAILED"); } } static function getPreSaveList() { global $adb; $cache = Cache::getInstance('sdk_presave',null,self::getCacheFolder()); $tmp = $cache->get(); if ($tmp === false && $adb->table_exist('sdk_presave')) { $tmp = array(); $result = $adb->query('select * from sdk_presave'); if ($result && $adb->num_rows($result)>0) { while($row=$adb->fetchByAssoc($result)) { $tmp[$row['presaveid']] = array('module'=>$row['module'],'src'=>$row['src']); } } $cache->set($tmp); } return $tmp; } static function getPreSave($module) { $preSave = self::getPreSaveList(); foreach($preSave as $id => $info) { if ($module == $info['module']) { return $info['src']; } } } static function getPopupQueries($type) { global $adb; $cache = Cache::getInstance('sdk_popup_query',null,self::getCacheFolder()); $tmp = $cache->get(); if ($tmp === false) { $tmp = array(); $result = $adb->query('select * from sdk_popup_query'); if ($result && $adb->num_rows($result)>0) { while($row=$adb->fetchByAssoc($result)) { $tmp[$row['type']][$row['id']] = array('module'=>$row['module'],'param'=>$row['param'],'src'=>$row['src'],'hidden_rel_fields'=>$row['hidden_rel_fields']); //crmv@26920 } } $cache->set($tmp); } return $tmp[$type]; } static function getJSPreSaveLis() { $tmp = self::getPreSaveList(); if (!empty($tmp)) { return Zend_Json::encode($tmp); } else { return ''; } } /** * $type: field/related -> popup open by field / popup open by field * $module : module from which popup is open * $param : if $type is field $param is the fieldname else il the destination module */ static function getPopupQuery($type,$module,$param) { $popupQueries = self::getPopupQueries($type); if (!empty($popupQueries)) { foreach($popupQueries as $info) { if ($module == $info['module'] && $param == $info['param']) { return $info['src']; } } //crmv@131239 crmv@180275 check for table fields if ($type == 'field' && substr_count($param,'_') == 2) { list($t,$f,$o) = explode('_',$param); return self::getPopupQuery($type,$module,"{$t}_{$f}"); } //crmv@131239e crmv@180275e } } //crmv@26920 static function getPopupHiddenElements($module,$param,$only_fields=false){ require_once('include/Zend/Json.php'); $popupQueries = self::getPopupQueries('field'); if (!empty($popupQueries)) { foreach($popupQueries as $info) { if ($module == $info['module'] && $param == $info['param'] && $info['hidden_rel_fields'] != '') { if (empty($hidden_fields)) { $hidden_fields = Zend_Json::decode(html_entity_decode($info['hidden_rel_fields'])); } if($only_fields === true){ return array_keys($hidden_fields); } if($only_fields == 'autocomplete'){ return html_entity_decode($info['hidden_rel_fields']); } $js_string = ''; $index = 0; if (!empty($hidden_fields)) { foreach($hidden_fields as $field =>$value ){ $js_string .= '&'.$field.'="+'.str_replace("\\","",$value); if($index < sizeof($hidden_fields)-1){ $js_string .= '+"'; } $index++; } } if($index > 0){ $js_string .= '+"'; } return $js_string; } } //crmv@131239 crmv@180275 check for table fields if (substr_count($param,'_') == 2) { list($t,$f,$o) = explode('_',$param); return self::getPopupHiddenElements($module,"{$t}_{$f}",$only_fields); } //crmv@131239e crmv@180275e } } //crmv@26920e static function setPopupQuery($type, $module, $param, $src, $hidden_rel_fields='') { //crmv@26920 global $adb; // check duplicates $file = self::getPopupQuery($type, $module, $param); if (isset($file) && !empty($file)) { self::log("Adding SDK Popup Query ($src) ... FAILED (duplicate)"); return; } $popupid = $adb->getUniqueID("sdk_popup_query"); //crmv@26920 $columns = 'id,type,module,param,src'; $params = array($popupid,$type,$module,$param,$src); if ($hidden_rel_fields != '') { $columns .= ',hidden_rel_fields'; $params[] = Zend_Json::encode($hidden_rel_fields); } $adb->pquery('insert into sdk_popup_query ('.$columns.') values ('.generateQuestionMarks($params).')',array($params)); //crmv@26920e self::log("Adding SDK Popup Query ($src) ... DONE"); self::clearSessionValue('sdk_popup_query'); } static function unsetPopupQuery($type, $module, $param, $src) { global $adb; $query = 'delete from sdk_popup_query where type = ? and module = ? and param = ? and src = ?'; $qpar = array($type, $module, $param, $src); $res = $adb->pquery($query, $qpar); if ($res && $adb->getAffectedRowCount($res) > 0) { self::log("Deleting SDK Popup Query ($src) ... DONE"); self::clearSessionValue('sdk_popup_query'); } else { self::log("Deleting SDK Popup Query ($src) ... FAILED"); } } static function getAdvancedQueries() { global $adb; $cache = Cache::getInstance('sdk_adv_query',null,self::getCacheFolder()); $tmp = $cache->get(); if ($tmp === false) { $tmp = array(); $result = $adb->query('select * from sdk_adv_query'); if ($result && $adb->num_rows($result)>0) { while($row=$adb->fetchByAssoc($result)) { $tmp[$row['module']] = array('src'=>$row['src'],'function'=>$row['function']); } } $cache->set($tmp); } return $tmp; } static function getAdvancedQuery($module) { $filter = ''; $advancedQuery = self::getAdvancedQueries(); if ($advancedQuery[$module] != '') { $src = $advancedQuery[$module]['src']; if ($src != '' && Vtecrm_Utils::checkFileAccess($src,false)) { require_once($src); $filter = $advancedQuery[$module]['function']($module); } } return $filter; } static function setAdvancedQuery($module, $func, $src) { global $adb; $qs = self::getAdvancedQueries(); if (array_key_exists($module, $qs)) { self::log("Adding SDK Advanced Query ($module) ... FAILED"); return; } $adqueryid = $adb->getUniqueID("sdk_adv_query"); $params = array($adqueryid,$module,$func, $src); $column = array('id','module','function','src'); $adb->format_columns($column); $adb->pquery('insert into sdk_adv_query ('.implode(',',$column).') values ('.generateQuestionMarks($params).')',array($params)); self::log("Adding SDK Advanced Query ($module) ... DONE"); self::clearSessionValue('sdk_adv_query'); } static function unsetAdvancedQuery($module) { global $adb; $query = 'delete from sdk_adv_query where module = ?'; $qpar = array($module); $res = $adb->pquery($query, $qpar); if ($res && $adb->getAffectedRowCount($res) > 0) { self::log("Deleting SDK Advanced Query ($module) ... DONE"); self::clearSessionValue('sdk_adv_query'); } else { self::log("Deleting SDK Advanced Query ($module) ... FAILED"); } } static function getAdvancedPermissions() { global $adb; $cache = Cache::getInstance('sdk_adv_permission',null,self::getCacheFolder()); $tmp = $cache->get(); if ($tmp === false) { $tmp = array(); $result = $adb->query('select * from sdk_adv_permission'); if ($result && $adb->num_rows($result)>0) { while($row=$adb->fetchByAssoc($result)) { $tmp[$row['module']] = array('src'=>$row['src'],'function'=>$row['function']); } } $cache->set($tmp); } return $tmp; } static function getAdvancedPermissionFunction($module) { $advancedPermission = self::getAdvancedPermissions(); if ($advancedPermission[$module] != '') { $src = $advancedPermission[$module]['src']; if ($src != '' && Vtecrm_Utils::checkFileAccess($src,false)) { require_once($src); return $advancedPermission[$module]['function']; } } } static function setAdvancedPermissionFunction($module, $func, $src) { global $adb; $qs = self::getAdvancedPermissions(); if (array_key_exists($module, $qs)) { self::log("Adding SDK Advanced Permission Function ($module) ... FAILED"); return; } $adqueryid = $adb->getUniqueID("sdk_adv_permission"); $params = array($adqueryid,$module,$func,$src); $column = array('id','module','function','src'); $adb->format_columns($column); $res = $adb->pquery('insert into sdk_adv_permission ('.implode(',',$column).') values ('.generateQuestionMarks($params).')',array($params)); if ($res && $adb->getAffectedRowCount($res) > 0) { self::log("Adding SDK Advanced Permission Function ($module) ... DONE"); self::clearSessionValue('sdk_adv_permission'); } else { self::log("Adding SDK Advanced Permission Function ($module) ... FAILED"); } } static function unsetAdvancedPermissionFunction($module) { global $adb; $query = 'delete from sdk_adv_permission where module = ?'; $qpar = array($module); $res = $adb->pquery($query, $qpar); if ($res && $adb->getAffectedRowCount($res) > 0) { self::log("Deleting SDK Advanced Permission Function ($module) ... DONE"); self::clearSessionValue('sdk_adv_permission'); } else { self::log("Deleting SDK Advanced Permission Function ($module) ... FAILED"); } } static function getClasses($all='') { global $adb; if (empty($adb->database) || !isModuleInstalled('SDK')) { return; } $cache = Cache::getInstance('sdk_class'.$all,null,self::getCacheFolder()); $tmp = $cache->get(); if ($tmp === false) { $tmp = array(); $result = $adb->query('select * from sdk_class'); if ($result && $adb->num_rows($result)>0) { while($row=$adb->fetchByAssoc($result)) { if ($all == '_all') { $tmp[$row['extends']] = array('module'=>$row['module'],'src'=>$row['src']); } elseif ($all == '_parent') { $tmp[$row['module']] = self::getParentModule($row['extends']); } else { $module = self::getSonModule($row['module']); $result1 = $adb->pquery('select * from sdk_class where module = ?',array($module)); if ($result1 && $adb->num_rows($result1)>0) { $tmp[$row['extends']] = array('module'=>$module,'src'=>$adb->query_result($result1,0,'src')); } } } } $cache->set($tmp); } return $tmp; } static function getSonModule($extends) { $classes = self::getClasses('_all'); if ($classes[$extends] != '') { return self::getSonModule($classes[$extends]['module']); } else { return $extends; } } static function getDirectSonModule($extends) { $classes = self::getClasses('_all'); if ($classes[$extends] != '') { return $classes[$extends]['module']; } else { return ''; } } static function getParentModule($module) { global $adb; $result = $adb->pquery('select extends from sdk_class where module = ?',array($module)); if ($result && $adb->num_rows($result)>0) { $extends = $adb->query_result($result,0,'extends'); $return = self::getParentModule($extends); if ($return != '') { $module = $return; } } return $module; } static function getClass($extends) { $classes_all = self::getClasses('_all'); $classes = self::getClasses(); if ($classes[$extends] != '') { return $classes[$extends]; } } /** * Extends the class $extends with the class $module (which is in $src) * Some classes are not allowed to be extended and it's not permitted to * derive a class more than once */ static function setClass($extends, $module, $src) { global $adb; // check for blacklisted classes $badclasses = array('Conditionals', 'Rss', 'VteRSS'); //crmv@31357+31355 if (in_array($extends, $badclasses)) { self::log("Adding SDK Class ($module) ... FAILED (Class is blacklisted)"); return; } // check if class has already been extended $classes = self::getClasses('_all'); if (in_array($extends, array_keys($classes))) { self::log("Adding SDK Class ($module) ... FAILED (Class already extended)"); return; } // update the database $classid = $adb->getUniqueID("sdk_class"); $params = array($classid,$extends,$module,$src); $res = $adb->pquery('insert into sdk_class (id,extends,module,src) values ('.generateQuestionMarks($params).')',array($params)); if ($res && $adb->getAffectedRowCount($res) > 0) { self::log("Adding SDK Class ($module) ... DONE"); self::clearSessionValue('sdk_class_all'); self::clearSessionValue('sdk_class_parent'); self::clearSessionValue('sdk_class'); } else { self::log("Adding SDK Class ($module) ... FAILED"); } } /** * Notes: deletes also all derived classes */ static function unsetClass($extends) { global $adb; // create array with all the sons $deletelist = array(); $ds = $extends; while (($ds = self::getDirectSonModule($ds)) != '') $deletelist[] = $ds; array_pop($deletelist); $deletelist = array_reverse($deletelist); $deletelist[] = $extends; // do the deletion // TODO: join all the queries in a combined one to speed up things foreach ($deletelist as $ext) { $query = 'delete from sdk_class where extends = ?'; $qpar = array($ext); $res = $adb->pquery($query, $qpar); if ($res && $adb->getAffectedRowCount($res) > 0) { self::log("Deleting SDK Class ($ext) ... DONE"); self::clearSessionValue('sdk_class_all'); self::clearSessionValue('sdk_class_parent'); self::clearSessionValue('sdk_class'); } else { self::log("Deleting SDK Class ($ext) ... FAILED"); } } } static function getViews($module,$mode) { global $adb, $sdk_mode; $skipView = $_REQUEST['skip_sdk_view'] ?? ''; if ($skipView == '1') return false; $sdk_mode = $mode; $cache = Cache::getInstance('sdk_view',null,self::getCacheFolder()); $tmp = $cache->get(); if ($tmp === false) { $tmp = array(); $result = $adb->query('select * from sdk_view order by module, sequence'); if ($result && $adb->num_rows($result)>0) { while($row=$adb->fetchByAssoc($result)) { $tmp[$row['module']][$row['sequence']] = array('src'=>$row['src'],'mode'=>$row['mode'],'on_success'=>$row['on_success']); } } $cache->set($tmp); } return $tmp[$module]; } static function checkReadonly($readonly_old,$readonly,$mode) { if ($mode == 'restrict') { $readonly = max($readonly,$readonly_old); } elseif ($mode == 'constrain') { //do nothing } } /** * Retrieves the last sequence number for the specified module */ private static function getLastViewSequence($module) { global $adb; $res = $adb->pquery('select max(sequence) from sdk_view where module = ?', array($module)); if ($res && $adb->num_rows($res) > 0) { $row = $adb->fetch_array($res); return intval($row[0]); } else { return 0; } } /** * Adds a new View at the end of the list (for that module) */ static function addView($module, $src, $mode, $success) { global $adb; $valid_modes = array('default'=>'restrict', 'constrain'); $valid_success = array('default'=>'continue', 'stop'); if (!in_array($mode, $valid_modes)) $mode = $valid_modes['default']; if (!in_array($success, $valid_success)) $success = $valid_success['default']; // check duplicates $query = 'select module from sdk_view where module = ? and src = ?'; $qparam = array($module, $src); $res = $adb->pquery($query, $qparam); if ($res && $adb->num_rows($res) > 0) { self::log("Adding SDK View ($module - $src) ... FAILED (duplicate)"); return; } $seq = self::getLastViewSequence($module) + 1; $viewid = $adb->getUniqueID("sdk_view"); $qparam = array($viewid, $module, $src, $seq, $mode, $success); $column=array("viewid","module","src","sequence","mode","on_success"); $adb->format_columns($column); $query = 'insert into sdk_view ('.implode(',',$column).') values ('.generateQuestionMarks($qparam).')'; $res = $adb->pquery($query, $qparam); if ($res && $adb->getAffectedRowCount($res) > 0) { self::log("Adding SDK View ($module - $src) ... DONE"); self::clearSessionValue('sdk_view'); } else { self::log("Adding SDK View ($module - $src) ... FAILED"); } } /** * Deletes a view */ static function deleteView($module, $src) { global $adb; $query = 'delete from sdk_view where module = ? and src = ?'; $qparam = array($module, $src); $res = $adb->pquery($query, $qparam); if ($res && $adb->getAffectedRowCount($res) > 0) { self::log("Deleting SDK View ($module - $src) ... DONE"); self::clearSessionValue('sdk_view'); } else { self::log("Deleting SDK View ($module - $src) ... FAILED"); } } /** * Returns an array of files/dirs associated with the module */ static function getExtraSrc($module) { global $adb; $ret = array(); $query = 'select src from sdk_extra_src where module = ?'; $qparam = array($module); $res = $adb->pquery($query, $qparam); if ($res && $adb->num_rows($res) > 0) { while ($row = $adb->fetch_array_no_html($res)) { $ret[] = $row[0]; } } return $ret; } /** * Adds a file/dir association */ static function setExtraSrc($module, $src) { global $adb; // check duplicates $query = 'select id from sdk_extra_src where module = ? and src = ?'; $qparam = array($module, $src); $res = $adb->pquery($query, $qparam); if ($res && $adb->num_rows($res) > 0) { self::log("Adding SDK Extra Src ($module - $src) ... FAILED (duplicate)"); return; } $srcid = $adb->getUniqueID("sdk_extra_src"); $qparam = array($srcid, $module, $src); $query = 'insert into sdk_extra_src (id, module, src) values ('.generateQuestionMarks($qparam).')'; $res = $adb->pquery($query, $qparam); if ($res && $adb->getAffectedRowCount($res) > 0) { self::log("Adding SDK Extra Src ($module - $src) ... DONE"); } else { self::log("Adding SDK Extra Src ($module - $src) ... FAILED"); } } /** * Deletes a file/dir association */ static function unsetExtraSrc($module, $src) { global $adb; $query = 'delete from sdk_extra_src where module = ? and src = ?'; $qparam = array($module, $src); $res = $adb->pquery($query, $qparam); if ($res && $adb->getAffectedRowCount($res) > 0) { self::log("Deleting SDK Extra Src ($module - $src) ... DONE"); } else { self::log("Deleting SDK Extra Src ($module - $src) ... FAILED"); } } static function getFiles($module) { global $adb; $cache = Cache::getInstance('sdk_file',null,self::getCacheFolder()); $tmp = $cache->get(); if ($tmp === false) { $tmp = array(); $result = $adb->query('select * from sdk_file order by module'); if ($result && $adb->num_rows($result)>0) { while($row=$adb->fetchByAssoc($result)) { $tmp[$row['module']][$row['file']] = $row['new_file']; } } $cache->set($tmp); } return $tmp[$module]; } static function getFile($module,$file) { $files = self::getFiles($module); return $files[$file]; } static function setFile($module,$file,$new_file) { global $adb; $not_permitted_modules = array('Home','Calendar','Events'); if ($module == '' || $file == '' || $new_file == '') { self::log("Adding SDK File ($new_file) ... FAILED (module, file or new_file empty!)"); return; } if (self::getFile($module,$file) != '') { self::log("Adding SDK File ($new_file) ... FAILED (new_file already registered for module $module and file $file)"); return; } $fileid = $adb->getUniqueID("sdk_file"); $params = array($fileid,$module,$file,$new_file); $column = array('fileid','module','file','new_file'); $adb->format_columns($column); $adb->pquery('insert into sdk_file ('.implode(',',$column).') values ('.generateQuestionMarks($params).')',array($params)); self::log("Adding SDK File ($new_file) ... DONE"); self::clearSessionValue('sdk_file'); } static function unsetFile($module,$file) { global $adb; $column = 'file'; $adb->format_columns($column); $res = $adb->pquery('delete from sdk_file where module = ? and '.$column.' = ?',array($module,$file)); if ($res && $adb->getAffectedRowCount($res) > 0) { self::log("Deleting SDK File ($module,$file) ... DONE"); self::clearSessionValue('sdk_file'); } else { self::log("Deleting SDK File ($module,$file) ... FAILED"); } } static function getHomeIframes() { global $adb,$table_prefix; $cache = Cache::getInstance('sdk_home_iframe',null,self::getCacheFolder()); $tmp = $cache->get(); if ($tmp === false) { $tmp = array(); $sizeCol = 'size'; $adb->format_columns($sizeCol); $sql = "SELECT sdk_home_iframe.stuffid, sdk_home_iframe.$sizeCol, sdk_home_iframe.iframe, sdk_home_iframe.url FROM sdk_home_iframe INNER JOIN {$table_prefix}_homestuff ON sdk_home_iframe.stuffid = {$table_prefix}_homestuff.stuffid UNION SELECT {$table_prefix}_homestuff.stuffid, sdk_home_global_iframe.$sizeCol, sdk_home_global_iframe.iframe, sdk_home_global_iframe.url FROM sdk_home_global_iframe INNER JOIN {$table_prefix}_homestuff ON {$table_prefix}_homestuff.stufftitle = sdk_home_global_iframe.name"; $result = $adb->query($sql); if ($result && $adb->num_rows($result)>0) { while ($row = $adb->fetchByAssoc($result)) { $tmp[$row['stuffid']] = $row; } } $cache->set($tmp); } return $tmp; } static function getGlobalIframes() { global $adb,$table_prefix; $cache = Cache::getInstance('sdk_home_global_iframes',null,self::getCacheFolder()); $tmp = $cache->get(); if ($tmp === false) { $tmp = array(); if (Vtecrm_Utils::CheckTable('sdk_home_global_iframe')) { $result = $adb->query('select * from sdk_home_global_iframe'); if ($result && $adb->num_rows($result)>0) { while ($row = $adb->fetchByAssoc($result)) { $tmp[$row['name']] = $row; } } } $cache->set($tmp); } return $tmp; } static function getGlobalFixedIframes() { global $adb,$table_prefix; $cache = Cache::getInstance('sdk_home_fixed_iframes',null,self::getCacheFolder()); $tmp = $cache->get(); if ($tmp === false) { $tmp = array(); $result = $adb->query('select * from '.$table_prefix.'_home_iframe'); if ($result && $adb->num_rows($result)>0) { while ($row = $adb->fetchByAssoc($result)) { $tmp[] = $row; } } $cache->set($tmp); } return $tmp; } static function getDefaultIframes($mode='plain'){ $session_name = 'sdk_home_default_iframes_'.$mode; $cache = Cache::getInstance($session_name,null,self::getCacheFolder()); $tmp = $cache->get(); if ($tmp === false) { $tmp = array(); $iframes = SDK::getGlobalFixedIframes(); foreach ($iframes as $iframe){ if ($mode != 'plain'){ $tmp['Iframe'][] = $iframe['hometype']; } else{ $tmp[] = $iframe['hometype']; } } $iframes = SDK::getGlobalIframes(); foreach ($iframes as $iframe){ if ($mode != 'plain'){ $tmp['SDKIframe'][] = $iframe['name']; } else{ $tmp[] = $iframe['name']; } } $cache->set($tmp); } return $tmp; } static function getHomeIframe($stuffid) { $iframes = self::getHomeIframes(); return $iframes[$stuffid]; } static function setHomeIframe($size, $url, $title, $userid = null, $useframe = true) { global $adb,$table_prefix; if (empty($url)) { self::log("Adding SDK Home Iframe ($url) ... FAILED (url empty)"); return; } // users if (is_null($userid)) { // all users $userid = array_keys(get_user_array(false)); } elseif (!is_array($userid)) { $userid = array($userid); } //duplicate $iframes = self::getHomeIframes(); if (!empty($iframes)) { foreach ($iframes as $id=>$idata) { if ($idata['url'] == htmlspecialchars($url) && in_array($idata['userid'], $userid)) { self::log("Adding SDK Home Iframe ($url) ... FAILED (url already registered)"); return; } } } // restrict size $size = max(1, min($size, 4)); $useframe = intval($useframe); foreach ($userid as $uid) { $iframeid = $adb->getUniqueID($table_prefix."_homestuff"); $column = array('stuffid','stuffsequence','stufftype','userid','visible','size','stufftitle'); $adb->format_columns($column); $params = array($iframeid,0,'SDKIframe', $uid, 0, $size, $title); $adb->pquery('insert into '.$table_prefix.'_homestuff ('.implode(',',$column).') values ('.generateQuestionMarks($params).')',array($params)); $params = array($iframeid,$size, $useframe, $url); $column = array('stuffid','size','iframe','url'); $adb->format_columns($column); $adb->pquery('insert into sdk_home_iframe ('.implode(',',$column).') values ('.generateQuestionMarks($params).')',array($params)); } self::log("Adding SDK Home Iframe ($url) ... DONE"); self::clearSessionValue('sdk_home_iframe'); } // todo: come parametro passare un array static function unsetHomeIframe($stuffid) { global $adb,$table_prefix; $res = $adb->pquery('delete from sdk_home_iframe where stuffid = ?', array($stuffid)); $res2 = $adb->pquery('delete from '.$table_prefix.'_homestuff where stuffid = ?', array($stuffid)); if ($res && $res2 && $adb->getAffectedRowCount($res) > 0) { self::log("Deleting SDK Home Iframe ($stuffid) ... DONE"); self::clearSessionValue('sdk_home_iframe'); } else { self::log("Deleting SDK Home Iframe ($stuffid) ... FAILED"); } } static function setHomeGlobalIframe($size, $url, $title,$useframe = true) { global $adb,$table_prefix; if (empty($url)) { self::log("Adding SDK Home Global Iframe ($url) ... FAILED (url empty)"); return; } //duplicate $iframes = self::getHomeIframes(); if (!empty($iframes)) { foreach ($iframes as $id=>$idata) { if ($idata['name'] == $title) { self::log("Adding SDK Home Iframe ($title) ... FAILED (title already registered)"); return; } } } $userid = array_keys(get_user_array(false)); // restrict size $size = max(1, min($size, 4)); $useframe = intval($useframe); $params = array($title,$size, $useframe, $url); $column = array('name','size','iframe','url'); $adb->format_columns($column); $adb->pquery('insert into sdk_home_global_iframe ('.implode(',',$column).') values ('.generateQuestionMarks($params).')',array($params)); //add homestuff and homedefault for every user foreach ($userid as $uid) { $result = $adb->pquery("SELECT * FROM {$table_prefix}_homestuff WHERE userid = ? AND stufftype = ? AND stufftitle = ?",array($uid,'SDKIframe',$title)); if ($result && $adb->num_rows($result) > 0) { //skip } else { $iframeid = $adb->getUniqueID($table_prefix."_homestuff"); $column = array('stuffid','stuffsequence','stufftype','userid','visible','size','stufftitle'); $adb->format_columns($column); $params = array($iframeid,0,'SDKIframe', $uid, 0, $size, $title); $adb->pquery('insert into '.$table_prefix.'_homestuff ('.implode(',',$column).') values ('.generateQuestionMarks($params).')',array($params)); $params_insert = Array( 'stuffid'=>$iframeid, 'hometype'=>$title, 'maxentries'=>0, 'setype'=>'NULL', ); $sql="insert into ".$table_prefix."_homedefault (".implode(",",array_keys($params_insert)).") values(".generateQuestionMarks($params_insert).")"; $adb->pquery($sql,$params_insert); } } self::log("Adding SDK Home Global Iframe ($url) ... DONE"); self::clearSessionValue('sdk_home_global_iframe'); } // todo: come parametro passare un array static function unsetHomeGlobalIframe($title) { global $adb,$table_prefix; $res = $adb->pquery('delete from sdk_home_global_iframe where name = ?', array($title)); if ($res && $adb->getAffectedRowCount($res) > 0) { //delete homestuff and homedefault for every user $params = array($title); $adb->pquery('delete from '.$table_prefix.'_homestuff where stufftitle = ?',$params); $adb->pquery('delete from '.$table_prefix.'_homedefault where hometype = ?',$params); self::log("Deleting SDK Home Global Iframe ($stuffid) ... DONE"); self::clearSessionValue('sdk_home_global_iframe'); } else { self::log("Deleting SDK Home Global Iframe ($stuffid) ... FAILED"); } } private static function getHomeIframeByUrl($url) { global $adb; $url = strtolower($url); $params = array($url); $query = 'select stuffid from sdk_home_iframe where lower(url) = ?'; $res = $adb->pquery($query, $params); $ret = array(); if ($res && $adb->num_rows($res) > 0) { while ($row = $adb->fetch_array($res)) { $ret[] = $row[0]; } } return $ret; } static function unsetHomeIframeByUrl($url) { global $adb; $ids = self::getHomeIframeByUrl($url); foreach ($ids as $id) { self::unsetHomeIframe($id); } } static function getMenuButton($type, $module='', $action='') { global $adb, $theme; $buttons = ''; $minImg = ''; $classLg = ''; if ($_COOKIE['crmvWinMaxStatus'] == 'close') { $minImg = '_min'; } else { $classLg = 'md-lg'; } if ($type == 'fixed') { $res = $adb->query('select * from sdk_menu_fixed order by id'); if ($res && $adb->num_rows($res) > 0) { while($row=$adb->fetchByAssoc($res,-1,false)) { //crmv@37303 $check = true; if (!empty($row['cond'])) { $cond = explode(':',$row['cond']); if (count($cond) == 2) { // crmv@OPER8071 if (file_exists($cond[1])){ require_once($cond[1]); $check = $cond[0]($row); } else { $check = false; } // crmv@OPER8071e } } if ($check) { $image = explode('.',$row['image']); // check if it has an extension, and use it as an image if ($image[1]) { $image = $image[0].$minImg.'.'.$image[1]; $buttons .= '