public function process(Vtiger_Request $request) { $adb = \PearDatabase::getInstance(); if (!\SwVtTools\VtUtils::existTable('vtiger_gcal_sync')) { $adb->query("CREATE TABLE IF NOT EXISTS `vtiger_gcal_sync` (\n `user_id` int(11) NOT NULL,\n `calendar_id` varchar(500) NOT NULL\n ) ENGINE=InnoDB;"); } }
public function handleEvent($handlerType, $entityData) { switch ($handlerType) { case 'vtiger.dispatch.before': return; require_once 'modules/SwVtTools/filecache.php'; $cacheFile = vglobal('root_directory') . '/modules/SwVtTools/cache/Module.php'; if (!file_exists($cacheFile) || $_REQUEST['clearcache'] == '1') { swtools_filecache(glob(vglobal('root_directory') . '/modules/*/models/Module.php'), $cacheFile); } require_once $cacheFile; break; case 'vtiger.process.customview.editajax.view.finish': if (empty(self::$DATA['recordId'])) { return; } $content = ob_get_contents(); ob_end_clean(); $customViewModel = CustomView_Record_Model::getInstanceById(self::$DATA['recordId']); $blocks = \SwVtTools\VtUtils::getFieldsWithBlocksForModule(self::$DATA['moduleName']); $html = '<h4 class="filterHeaders">Filter Sort Order:</h4><br/>'; $html .= '<div class="contentsBackground well">'; $html .= ' <table cellpadding="4" cellspacing="0" width="100%" border="0"> <tbody><tr> <td class="dvtCellInfo" width="5%" align="right">Column: </td> <td class="dvtCellInfo" width="20%"> <select name="order_col" id="order_col" class="chzn-select"> <option value="">' . getTranslatedString('LBL_NONE') . '</option>'; foreach ($blocks as $blockLabel => $fields) { $html .= '<optgroup label="' . $blockLabel . '">'; foreach ($fields as $field) { $html .= '<option ' . ($customViewModel->get('order_col') == $field->name ? 'selected="selected"' : '') . ' value="' . $field->name . '">' . $field->label . '</option>'; } $html .= '</optgroup>'; } $html .= '</select> </td> <td class="dvtCellInfo" width="20%"> <select name="order_dir" id="order_dir" class="small"> <option value="ASC" ' . ($customViewModel->get('order_dir') == 'ASC' ? 'selected="selected"' : '') . '>↑ ASC Ascending</option> <option value="DESC" ' . ($customViewModel->get('order_dir') == 'DESC' ? 'selected="selected"' : '') . '>↓ DESC Descending</option> </select> </td> <td class="dvtCellInfo" width="10%" align="right">numerische Sortierung: </td> <td class="dvtCellInfo" width="15%"> <input type="checkbox" name="order_numeric_check" value="1" ' . ($customViewModel->get('order_numeric_check') > 0 ? 'checked="checked"' : '') . '> Skip Chars: <input type="text" alt="ignore the first X chars to get a numberic value" title="ignore the first X chars to get a numberic value" style="width:20px;" name="order_numeric" value="' . $customViewModel->get('order_numeric') . '"> </td></tr></table>'; $html .= '</div>'; $content = str_replace('<div class="filterActions">', $html . '<div class="filterActions">', $content); echo $content; break; } }
public function process(Vtiger_Request $request) { $adb = PearDatabase::getInstance(); //$params = $request->getAll(); $post = $request->getAll(); if (!empty($post['filterId'])) { $filterId = $post['filterId']; $data = array(); $columns = array(); $sql = 'SELECT * FROM vtiger_customview WHERE cvid = ?'; $data['vtiger_customview'] = $adb->fetchByAssoc($adb->pquery($sql, array($filterId))); $sql = 'SELECT * FROM vtiger_cvcolumnlist WHERE cvid = ?'; $result = $adb->pquery($sql, array($filterId)); while ($row = $adb->fetchByAssoc($result)) { $data['vtiger_cvcolumnlist'][] = $row; $parts = explode(':', $row['columnname']); $columns[] = array($parts[0], $parts[2], $row['columnname']); } $sql = 'SELECT * FROM vtiger_cvstdfilter WHERE cvid = ?'; $result = $adb->pquery($sql, array($filterId)); while ($row = $adb->fetchByAssoc($result)) { $data['vtiger_cvstdfilter'][] = $row; } $sql = 'SELECT * FROM vtiger_cvadvfilter_grouping WHERE cvid = ?'; $result = $adb->pquery($sql, array($filterId)); while ($row = $adb->fetchByAssoc($result)) { $data['vtiger_cvadvfilter_grouping'][] = $row; } $sql = 'SELECT * FROM vtiger_cvadvfilter WHERE cvid = ?'; $result = $adb->pquery($sql, array($filterId)); while ($row = $adb->fetchByAssoc($result)) { $data['vtiger_cvadvfilter'][] = $row; $parts = explode(':', $row['columnname']); $columns[] = array($parts[0], $parts[2], $row['columnname']); } foreach ($columns as $col) { $sql = 'SELECT * FROM vtiger_field WHERE tablename = ? AND fieldname = ?'; $result = $adb->pquery($sql, array($col[0], $col[1])); $field = $adb->fetchByAssoc($result); $data['columns'][] = array($field['fieldname'], \SwVtTools\VtUtils::getModuleName($field['tabid']), $field['fieldlabel'], $field['uitype'], $col[2]); } global $vtiger_current_version; //$vtiger_current_version = '6.0.0'; $data['system'] = array('vtiger_version' => $vtiger_current_version); $data = base64_encode(serialize($data)); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT\n"); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Content-Disposition: attachment; filename=\"customview_" . intval($filterId) . ".cv\";"); header("Content-Type: application/force-download"); header('Content-Description: File Transfer'); echo $data; } }
function checkDB() { $adb = \PearDatabase::getInstance(); if (!\SwVtTools\VtUtils::existTable("vtiger_tools_sidebar")) { echo "Create table vtiger_tools_sidebar ... ok<br>"; $adb->query("CREATE TABLE IF NOT EXISTS `vtiger_tools_sidebar` (\n `id` mediumint(8) unsigned NOT NULL,\n `active` TINYINT(1) NOT NULL,\n `tabid` mediumint(8) NOT NULL,\n `content` TEXT NOT NULL,\n `title` VARCHAR(128) NOT NULL,\n PRIMARY KEY (`id`)\n ) ENGINE=InnoDB;"); } if (!\SwVtTools\VtUtils::existTable("vtiger_tools_sidebar_seq")) { echo "Create table vtiger_tools_sidebar_seq ... ok<br>"; $adb->query("CREATE TABLE IF NOT EXISTS `vtiger_tools_sidebar_seq` (\n `id` mediumint(8) unsigned NOT NULL\n ) ENGINE=InnoDB;"); $adb->query("INSERT INTO vtiger_tools_sidebar_seq SET id = 1"); } }
* Created by JetBrains PhpStorm. * User: Stefan Warnat <*****@*****.**> * Date: 31.10.14 13:06 * You must not use this file without permission. */ require_once 'modules/SwVtTools/lib/SwVtTools/VtUtils.php'; $adb = \PearDatabase::getInstance(); if (empty($current_language)) { $current_language = 'en_us'; } $app_strings = return_application_language($current_language); $sql = 'SELECT * FROM vtiger_google_sync WHERE googlemodule = "Calendar"'; $result = $adb->query($sql); $oldCurrentUser2 = vglobal('current_user'); $enableSharedCalendar = false; if (\SwVtTools\VtUtils::existTable('vtiger_gcal_sync')) { $enableSharedCalendar = true; } $listView = new Google_List_View(); echo 'GoogleCal Sync' . PHP_EOL; while ($user = $adb->fetchByAssoc($result)) { $user2 = CRMEntity::getInstance('Users'); $user2->retrieveCurrentUserInfoFromFile($user['user']); vglobal('current_user', $user2); $controller = new Google_Calendar_Controller($user2); if ($enableSharedCalendar === true && method_exists($controller, 'getCalendarId')) { $calId = $controller->getCalendarId(); $controller->setCalendarId($calId); } if ($enableSharedCalendar === true && !method_exists($controller, 'getCalendarId')) { $enableSharedCalendar = false;
public function process(Vtiger_Request $request) { $adb = \PearDatabase::getInstance(); $viewer = $this->getViewer($request); if (!empty($_GET['delSidebar'])) { $sql = "DELETE FROM vtiger_tools_sidebar WHERE id = " . intval($_GET["delSidebar"]); $adb->query($sql); $linkurl = 'module=SwVtTools&view=SidebarWidget&sID=' . intval($_GET["delSidebar"]) . ''; $sql = "DELETE FROM vtiger_links WHERE linkurl = '" . $linkurl . "'"; $adb->query($sql); } if (!empty($_POST['tool_action'])) { switch ($_POST['tool_action']) { case 'saveSidebar': $sql = "UPDATE vtiger_tools_sidebar SET title = ?, content = ?, active = ? WHERE id = ?"; $adb->pquery($sql, array($_POST["title"], $_POST["content"], $_POST["active"] == "1" ? 1 : 0, $_POST["sidebar_id"])); $linkurl = 'module=SwVtTools&view=SidebarWidget&sID=' . intval($_POST["sidebar_id"]) . ''; echo '<div class="alert alert-success" style="padding:10px;">Sidebar was saved successfully!</div>'; if ($_POST["active"] == "1") { $sql = "SELECT * FROM vtiger_links WHERE linkurl = ?"; $result = $adb->pquery($sql, array($linkurl)); if ($adb->num_rows($result) == 0) { $linkid = $adb->getUniqueID("vtiger_links"); $sql = "INSERT INTO vtiger_links SET linkid = " . $linkid . ", tabid = ?, linktype = 'DETAILVIEWSIDEBARWIDGET', linklabel = ?, linkurl = ?"; $adb->pquery($sql, array(intval($_POST["sidebar_tabid"]), $_POST["title"], $linkurl)); } else { } } else { $sql = "DELETE FROM vtiger_links WHERE linkurl = ?"; $adb->pquery($sql, array($linkurl)); } break; case 'createSidebar': $nextID = $adb->getUniqueID("vtiger_tools_sidebar"); $sql = "INSERT INTO vtiger_tools_sidebar SET id = " . $nextID . ", active = 0, tabid = " . intval($_POST["sidebar_module"]) . ", content = '', title = 'Sidebar " . $nextID . "'"; $adb->query($sql); break; case 'createRelation': include_once 'vtlib/Vtiger/Module.php'; if (empty($_POST['label'])) { echo '<div class="alert alert-danger" style="padding:10px;">You don\'t set relation label!</div>'; } else { $fromInstance = Vtiger_Module::getInstance(\SwVtTools\VtUtils::getModuleName($_POST['tabid'])); $toModuleName = \SwVtTools\VtUtils::getModuleName($_POST['related_tabid']); $toInstance = Vtiger_Module::getInstance($toModuleName); $reltype = $_POST['reltype'] == 'get_dependents_list' ? 'get_dependents_list' : 'get_related_list'; $fromInstance->setRelatedlist($toInstance, $_POST['label'], array('add', 'select'), $toModuleName == 'Documents' ? 'get_attachments' : $reltype); echo '<div class="alert alert-success" style="padding:10px;">Relation was created</div>'; } break; case 'makeCvToDefault': $defaultCustomView = array(); foreach ($_POST['filterIds'] as $filterId) { $sql = 'SELECT entitytype FROM vtiger_customview WHERE cvid = ' . $filterId; $result = $adb->query($sql); if ($adb->num_rows($result) == 0) { continue; } $defaultCustomView[getTabId($adb->query_result($result, 0, 'entitytype'))] = $filterId; } foreach ($_POST['userIds'] as $userId) { foreach ($defaultCustomView as $tabid => $cvid) { $sql = 'REPLACE INTO vtiger_user_module_preferences SET userid = ' . $userId . ', tabid = ' . $tabid . ',default_cvid = ' . $cvid; $adb->query($sql, true); } } break; case 'cv_import1': if (is_uploaded_file($_FILES['customview']['tmp_name'])) { $content = base64_decode(trim(file_get_contents($_FILES['customview']['tmp_name']))); $key = md5($content . microtime(false)); $content = unserialize($content); global $vtiger_current_version; if ($vtiger_current_version != $content['system']['vtiger_version']) { $viewer->assign('showCVImportError', 'The exported vtiger version [' . $content['system']['vtiger_version'] . '] does not match with the current one [' . $vtiger_current_version . ']! This isn\'t Possible'); } else { $viewer->assign('showCVImportError', false); $entityType = $request->get('cvImportModule'); if (empty($entityType)) { $entityType = $content['vtiger_customview']['entitytype']; } $content['entityType'] = $entityType; $_SESSION['filterimport'][$key] = $content; $viewer->assign('importKey', $key); $columns = $content['columns']; $viewer->assign('filter_columns', $content['columns']); $availableFields = \SwVtTools\VtUtils::getFieldsForModule($entityType); $fields = array(); foreach ($availableFields as $field) { $fields[$field->name] = $field; } foreach ($columns as $index => $value) { if (isset($fields[$value[0]])) { $columns[$index][5] = $value[0]; } } $viewer->assign('import_available_fields', $availableFields); $viewer->assign('cvImportColumns', $columns); } } break; case 'cv_import2': $content = $_SESSION['filterimport'][$request->get('cvImportKey')]; $columns = $request->get('column'); $moduleModel = Vtiger_Module_Model::getInstance($content['entityType']); $resultColumns = array(); foreach ($content['columns'] as $index => $value) { $fieldInfo = $moduleModel->getField($columns[$value[0]]); $columnName = $fieldInfo->getCustomViewColumnName(); //$content['columns'][$index][4] = $columnName; $resultColumns[$value[4]] = $columnName; } $cvid = $adb->getUniqueID('vtiger_customview'); $current_user = Users_Record_Model::getCurrentUserModel(); $whiteList = array('cvid', 'viewname', 'setdefault', 'setmetrics', 'entitytype', 'status'); $content['vtiger_customview']['userid'] = $current_user->getId(); $content['vtiger_customview']['viewname'] = $request->get('filterName'); $content['vtiger_customview']['cvid'] = $cvid; $query = $this->_generateSQLValues($content['vtiger_customview'], $whiteList); $adb->pquery('INSERT INTO vtiger_customview SET ' . $query['query'], $query['bind'], true); $whiteList = array('cvid', 'columnindex', 'columnname'); foreach ($content['vtiger_cvcolumnlist'] as $record) { $record['cvid'] = $cvid; $record['columnname'] = $resultColumns[$record['columnname']]; $query = $this->_generateSQLValues($record, $whiteList); $adb->pquery('INSERT INTO vtiger_cvcolumnlist SET ' . $query['query'], $query['bind'], true); } if (!empty($content['vtiger_cvstdfilter']) && is_array($content['vtiger_cvstdfilter'])) { $whiteList = array('cvid', 'columnindex', 'stdfilter', 'startdate', 'enddate'); foreach ($content['vtiger_cvstdfilter'] as $record) { $record['cvid'] = $cvid; $record['columnname'] = $resultColumns[$record['columnname']]; $query = $this->_generateSQLValues($record, $whiteList); $adb->pquery('INSERT INTO vtiger_cvstdfilter SET ' . $query['query'], $query['bind'], true); } } if (!empty($content['vtiger_cvadvfilter_grouping']) && is_array($content['vtiger_cvadvfilter_grouping'])) { $whiteList = array('cvid', 'groupid', 'group_condition', 'condition_expression'); foreach ($content['vtiger_cvadvfilter_grouping'] as $record) { $record['cvid'] = $cvid; $query = $this->_generateSQLValues($record, $whiteList); $adb->pquery('INSERT INTO vtiger_cvadvfilter_grouping SET ' . $query['query'], $query['bind'], true); } } if (!empty($content['vtiger_cvadvfilter']) && is_array($content['vtiger_cvadvfilter'])) { $whiteList = array('cvid', 'columnindex', 'columnname', 'comparator', 'value', 'groupid', 'column_condition'); foreach ($content['vtiger_cvadvfilter'] as $record) { $record['cvid'] = $cvid; $record['columnname'] = $resultColumns[$record['columnname']]; $query = $this->_generateSQLValues($record, $whiteList); $adb->pquery('INSERT INTO vtiger_cvadvfilter SET ' . $query['query'], $query['bind'], true); } } break; } } if (!empty($_GET['editSidebar'])) { $sql = 'SELECT * FROM vtiger_tools_sidebar WHERE id = ?'; $result = $adb->pquery($sql, array($_GET["editSidebar"]), true); $sidebarData = $adb->fetchByAssoc($result); $sidebarData['moduleName'] = \SwVtTools\VtUtils::getModuleName($sidebarData['tabid']); $viewer->assign('editSidebar', $sidebarData); } $moduleName = $request->getModule(); $qualifiedModuleName = $request->getModule(false); $sql = 'SELECT user_name, id, first_name, last_name FROM vtiger_users'; $result = $adb->query($sql, true); while ($row = $adb->fetchByAssoc($result)) { $users[] = $row; } $viewer->assign('availableUsers', $users); $sql = 'SELECT * FROM vtiger_links WHERE linktype = "HEADERSCRIPT" and linklabel = "ToolsGermanNumbers" LIMIT 1'; $result = $adb->pquery($sql); if ($adb->num_rows($result) > 0) { $viewer->assign('comma_numbers_enabled', true); } else { $viewer->assign('comma_numbers_enabled', false); } $sql = 'SELECT * FROM vtiger_cron_task WHERE name = ?'; $result = $adb->pquery($sql, array('SWVTTool GoogleCalSync')); if ($adb->num_rows($result) > 0) { $viewer->assign('gcal_autosync', true); } else { $viewer->assign('gcal_autosync', false); } $entityModules = \SwVtTools\VtUtils::getEntityModules(true); $viewer->assign('entityModules', $entityModules); $sql = 'SELECT * FROM vtiger_customview ORDER BY entitytype'; $result = $adb->query($sql, true); $customViews = array(); while ($filter = $adb->fetchByAssoc($result)) { $customViews[$filter['cvid']] = $filter['entitytype'] . ' - ' . $filter['viewname']; } $viewer->assign('customViews', $customViews); $sql = 'SELECT * FROM vtiger_tools_sidebar ORDER BY tabid'; $result = $adb->query($sql, true); $sidebars = array(); while ($row = $adb->fetchByAssoc($result)) { $row['moduleName'] = \SwVtTools\VTUtils::getModuleName($row["tabid"]); $sidebars[] = $row; } $sql = 'SELECT MAX(laststart) as timestart FROM vtiger_cron_task'; $result = $adb->query($sql); if (time() - $adb->query_result($result, 0, 'timestart') > 86400) { $viewer->assign('show_cron_warning', true); } $EventHandlerActive = class_exists('EventHandler_Module_Model') && vtlib_isModuleActive('EventHandler') && strpos(file_get_contents(vglobal('root_directory') . '/modules/Vtiger/models/ListView.php'), 'EventHandler_Module_Model::do_filter') !== false; $viewer->assign('EventHandlerActive', $EventHandlerActive); $viewer->assign('sidebars', $sidebars); $viewer->view('Index.tpl', $qualifiedModuleName); }