public function render($tpl = null) { //authenticate the current user to make sure they are an admin UsersHelper::authenticateAdmin(); $app = \Cobalt\Container::fetch('app'); $document = $app->getDocument(); $document->addScript(JURI::base() . 'src/Cobalt/media/js/cobalt-admin.js'); /** Menu Links **/ $menu = MenuHelper::getMenuModules(); $this->menu = $menu; $configModel = new ConfigModel(); /** Component version **/ $installedVersion = ConfigHelper::getVersion(); $latestVersion = VersionHelper::getLatestVersion(); $updateUrl = "http://www.cobaltcrm.org/support/login"; $updatesFeed = $configModel->getUpdatesRSS(); /** Launch completion **/ $config = $configModel->getConfig(); $this->launch_default = $config->launch_default; $percentage = $menu['percentage']; $this->setup_percent = $percentage; /** php version check **/ $this->php_version = (double) phpversion(); $this->php_version_check = $this->php_version >= 5.3 ? TRUE : FALSE; /** View Ref **/ $this->installedVersion = $installedVersion; $this->latestVersion = $latestVersion; $this->updateUrl = $updateUrl; $this->updatesFeed = $updatesFeed; //display return parent::render(); }
public function render($tpl = null) { //authenticate the current user to make sure they are an admin UsersHelper::authenticateAdmin(); //display toolbar $this->toolbar = new Toolbar(); $this->toolbar->save(); //document $document = JFactory::getDocument(); $document->addScript(JURI::base() . "/src/Cobalt/media/js/cobalt-admin.js"); /* Menu Links **/ $menu = MenuHelper::getMenuModules(); $this->menu = $menu; //get model $model = new ConfigModel(); $layout = $this->getLayout(); $model->set("_layout", $layout); //get config $config = $model->getConfig(); //generate timezones $list = timezone_identifiers_list(); $timezones = array(); foreach ($list as $zone) { $timezones[$zone] = $zone; } //view references $this->imap_found = function_exists('imap_open') ? TRUE : FALSE; $this->config = $config; $this->timezones = $timezones; $this->time_formats = DateHelper::getTimeFormats(); $this->languages = ConfigHelper::getLanguages(); $this->language = ConfigHelper::getLanguage(); //display return parent::render(); }
public static function script($string = NULL, $jsSafe = false, $interpretBackSlashes = true) { $newString = JText::_($string, $jsSafe, $interpretBackSlashes); $configValues = ConfigHelper::getNamingConventions(); foreach ($configValues as $key => $value) { $key = str_replace("lang_", "", $key); $newString = self::ext_str_ireplace($key, $value, $newString); } // Normalize the key and translate the string. parent::$strings[strtoupper($string)] = $newString; return parent::$strings; }
public function removeSampleData() { $sampleIds = unserialize(ConfigHelper::getConfigValue('import_sample')); $db = $this->container->resolve('db'); $query = $db->getQuery(true); foreach ($sampleIds as $table => $ids) { $query->clear()->delete("#__" . $table)->where("id IN(" . implode(',', $ids) . ")"); $db->setQuery($query); $db->query(); } $data = array('import_sample' => "0"); $configModel = new ConfigModel(); $configModel->store($data); $msg = TextHelper::_('COBALT_SAMPLE_DATA_REMOVED'); $this->getApplication()->redirect('index.php?view=import', $msg); }
public static function getMenuModules() { $modules = array(); $app = \Cobalt\Container::fetch('app'); /** Side menu links **/ $menu_links = MenuHelper::getMenuLinks(); $menu = ViewHelper::getView('cobalt', 'menu', 'phtml'); $menu->menu_links = $menu_links; $modules['menu'] = $menu; /** Quick Menu Links **/ $quick_menu_links = MenuHelper::getQuickMenuLinks(); $quick_menu = ViewHelper::getView('cobalt', 'quick_menu', 'phtml'); $quick_menu->quick_menu_links = $quick_menu_links; $modules['quick_menu'] = $quick_menu; /** Determine help type on page **/ $help_type_1 = $app->input->get('view') != '' || !is_null($app->input->get('view')) ? $app->input->get('view') : $app->input->get('controller'); $help_type_2 = $app->input->get('layout') != '' || !is_null($app->input->get('layout')) ? $app->input->get('layout') : $app->input->get('task'); $help_type_1 = $help_type_1 == "" || is_null($help_type_1) ? "" : $help_type_1; $help_type_2 = $help_type_2 == "" || is_null($help_type_2) ? "" : '_' . $help_type_2; $help_type = str_replace(".", "_", $help_type_1 . $help_type_2); $help_types = self::getHelpTypes(); $show_help = ConfigHelper::getConfigValue('show_help'); $launch_default = ConfigHelper::getConfigValue('launch_default'); $step_completed = ConfigHelper::getConfigValue($help_type); $show_update_buttons = in_array($help_type, $help_types); /** Help Menu Links **/ $help_menu_links = MenuHelper::getHelpMenuLinks(); $help_menu = ViewHelper::getView('cobalt', 'help_menu', 'phtml'); $help_menu->help_menu_links = $help_menu_links; $help_menu->help_type = $help_type; $help_menu->show_help = $show_help; $help_menu->launch_default = $launch_default; $help_menu->step_completed = $step_completed; $help_menu->show_update_buttons = $show_update_buttons; $modules['help_menu'] = $help_menu; $count = count($help_menu_links) - 1; $completed = 0; foreach ($help_menu_links as $link) { if ($link['completed_status'] == 1) { $completed++; } } $modules['percentage'] = number_format($completed / $count * 100, 0); return $modules; }
public function store($data = null) { $app = \Cobalt\Container::fetch('app'); //Load Tables $row = new ConfigTable(); $data = isset($data) && is_array($data) && count($data) > 0 ? $data : $app->input->getRequest('post'); //date generation $date = date('Y-m-d H:i:s'); $data['id'] = 1; if (!array_key_exists('id', $data)) { $data['created'] = $date; } $data['modified'] = $date; if (array_key_exists('imap_pass', $data)) { $data['imap_pass'] = base64_encode($data['imap_pass']); } $data['show_help'] = array_key_exists('show_help', $data) ? $data['show_help'] : 0; if (array_key_exists("site_language", $data)) { ConfigHelper::saveLanguage($data['site_language']); unset($data['site_language']); } // Bind the form fields to the table if (!$row->bind($data)) { $this->setError($this->db->getErrorMsg()); return false; } // Make sure the record is valid if (!$row->check()) { $this->setError($this->db->getErrorMsg()); return false; } // Store the web link table to the database if (!$row->store()) { $this->setError($this->db->getErrorMsg()); return false; } return true; }
/** * Prepare HTML field templates for each dataTable column. * * @param string column name * @param object of item * @return string HTML template for propper field */ public function getDataTableFieldTemplate($column, $item) { switch ($column) { case 'id': $template = '<input type="checkbox" class="export" name="ids[]" value="' . $item->id . '" />'; break; case 'name': $template = '<a href="' . RouteHelper::_('index.php?view=deals&layout=deal&id=' . $item->id) . '">' . $item->name . '</a>'; break; case 'company_name': $template = '<a href="' . RouteHelper::_('index.php?view=companies&layout=company&id=' . $item->company_id) . '">' . $item->company_name . '</a>'; break; case 'amount': $template = ConfigHelper::getCurrency() . $item->amount; break; case 'status_name': if (!isset($item->status_id) || !$item->status_id) { $item->status_name = TextHelper::_('COBALT_CLICK_TO_EDIT'); } $statuses = DealHelper::getStatuses(null, true); $template = '<div class="dropdown">'; $template .= ' <a href="#" class="dropdown-toggle update-toggle-html" role="button" data-toggle="dropdown" id="deal_status_' . $item->id . '_link">'; $template .= ' <span class="deal-status-' . $item->status_name . '">' . $item->status_name . '</span>'; $template .= ' </a>'; $template .= ' <ul class="dropdown-menu" aria-labelledby="deal_status_' . $item->id . '" role="menu">'; if (isset($statuses) && count($statuses)) { foreach ($statuses as $id => $name) { $template .= ' <li>'; $template .= ' <a href="#" class="status_select dropdown_item" data-field="status_id" data-item="deal" data-item-id="' . $item->id . '" data-value="' . $id . '">'; $template .= ' <span class="deal-status-' . OutputFilter::stringURLUnicodeSlug($name) . '">' . $name . '</span>'; $template .= ' </a>'; $template .= ' </li>'; } } $template .= ' </ul>'; $template .= ' </div>'; break; case 'stage_name': if (!isset($item->stage_id) || !$item->stage_id) { $item->stage_name = TextHelper::_('COBALT_CLICK_TO_EDIT'); } $stages = DealHelper::getStages(null, true); $template = '<div class="dropdown">'; $template .= ' <a href="#" class="dropdown-toggle update-toggle-html" role="button" data-toggle="dropdown" id="deal_stage_' . $item->id . '_link">'; $template .= ' <span class="deal-stage-' . $item->stage_name . '">' . $item->stage_name . '</span>'; $template .= ' </a>'; $template .= ' <ul class="dropdown-menu" aria-labelledby="deal_stage_' . $item->id . '" role="menu">'; if (isset($stages) && count($stages)) { foreach ($stages as $id => $name) { $template .= ' <li>'; $template .= ' <a href="#" class="stage_select dropdown_item" data-field="stage_id" data-item="deal" data-item-id="' . $item->id . '" data-value="' . $id . '">'; $template .= ' <span class="deal-stage-' . OutputFilter::stringURLUnicodeSlug($name) . '">' . $name . '</span>'; $template .= ' </a>'; $template .= ' </li>'; } } $template .= ' </ul>'; $template .= ' </div>'; break; case 'source_name': if (!isset($item->source_id) || !$item->source_id) { $item->source_name = TextHelper::_('COBALT_CLICK_TO_EDIT'); } $sources = DealHelper::getSources(null, true); $template = '<div class="dropdown">'; $template .= ' <a href="#" class="dropdown-toggle update-toggle-html" role="button" data-toggle="dropdown" id="deal_source_' . $item->id . '_link">'; $template .= ' <span class="deal-source-' . $item->source_name . '">' . $item->source_name . '</span>'; $template .= ' </a>'; $template .= ' <ul class="dropdown-menu" aria-labelledby="deal_source_' . $item->id . '" role="menu">'; if (isset($sources) && count($sources)) { foreach ($sources as $id => $name) { $template .= ' <li>'; $template .= ' <a href="#" class="source_select dropdown_item" data-field="source_id" data-item="deal" data-item-id="' . $item->id . '" data-value="' . $id . '">'; $template .= ' <span class="deal-source-' . OutputFilter::stringURLUnicodeSlug($name) . '">' . $name . '</span>'; $template .= ' </a>'; $template .= ' </li>'; } } $template .= ' </ul>'; $template .= ' </div>'; break; case 'expected_close': if ($item->expected_close == "0000-00-00 00:00:00") { $template = TextHelper::_('COBALT_NOT_SET'); } else { $template = DateHelper::formatDate($item->expected_close); } break; case 'actual_close': if ($item->actual_close == "0000-00-00 00:00:00") { $template = TextHelper::_('COBALT_ACTIVE_DEAL'); } else { $template = DateHelper::formatDate($item->actual_close); } break; case 'action': $template = '<div class="btn-group">'; // @TODO: make these 2 buttons work // $template .= ' <a rel="tooltip" title="'.TextHelper::_('COBALT_VIEW_CONTACTS').'" data-placement="bottom" class="btn" href="javascript:void(0);" onclick="Cobalt.showDealContactsDialogModal('.$item->id.');"><i class="glyphicon glyphicon-user"></i></a>'; // $template .= ' <a rel="tooltip" title="'.TextHelper::_('COBALT_VIEW_NOTES').'" data-placement="bottom" class="btn" href="javascript:void(0);" onclick="openNoteModal(\'.deal->id.\',\'deal\');"><i class="glyphicon glyphicon-file"></i></a>'; $template .= ' <a data-toggle="popover" title="' . TextHelper::_('COBALT_VIEW_DETAILS') . '" data-placement="top" data-html="true" data-content-class="extras-' . $item->id . '" class="btn btn-xs btn-default" href="#" tabindex="0"><i class="glyphicon glyphicon-info-sign"></i></a>'; $template .= '</div>'; $template .= '<div class="extras-' . $item->id . ' hide">'; $template .= ' <b>' . TextHelper::_('COBALT_PRIMARY_CONTACT') . '</b>'; $template .= ' <a href="' . RouteHelper::_('index.php?view=people&layout=person&id=' . $item->primary_contact_id) . '">' . $item->primary_contact_first_name . '</a><br>'; $template .= ' <b>' . TextHelper::_('COBALT_NEXT_ACTION') . '</b><br>'; $template .= '</div>'; break; default: if (isset($column) && isset($item->{$column})) { $template = $item->{$column}; } else { $template = ''; } break; } return $template; }
/** * Get custom field values from picklists // forecasts // otherwise return the value as it was an input field */ public static function getCustomValue($customType, $customNameOrId, $customValue, $itemId) { $db = \Cobalt\Container::fetch('db'); $query = $db->getQuery(true); $id = str_replace("custom_", "", $customNameOrId); $query->select("c.type,c.values")->from("#__" . $customType . "_custom AS c")->where("c.id=" . $id); $db->setQuery($query); $custom = $db->loadObject(); switch ($custom->type) { case "forecast": $query->clear(); $query->select("(d.amount * ( d.probability / 100 )) AS amount")->from("#__deals AS d")->where("d.id=" . $itemId); $db->setQuery($query); $result = $db->loadResult(); return ConfigHelper::getCurrency() . $result; break; case "currency": return ConfigHelper::getCurrency() . $customValue; break; case "picklist": $values = json_decode($custom->values); return array_key_exists($customValue, $values) ? $values[$customValue] : TextHelper::_('COBALT_NONE'); break; case "date": return DateHelper::formatDate($customValue); break; default: return $customValue; break; } return $customValue; }
public function store() { //Load Tables $row = new UserTable(); $data = $this->app->input->post->getArray(); //$this->app->triggerEvent('onBeforeCRMUserSave', array(&$data)); //date generation $date = date('Y-m-d H:i:s'); if (!array_key_exists('id', $data)) { $data['created'] = $date; $data['time_zone'] = ConfigHelper::getConfigValue('timezone'); $data['time_format'] = ConfigHelper::getConfigValue('time_format'); $data['block'] = 0; $data['registerDate'] = $date; $data['activation'] = 0; $data['params'] = ""; } if (array_key_exists('password', $data) && $data['password'] != "") { $data['password'] = UsersHelper::hashPassword($data['password']); } else { unset($data['password']); } //generate team data $model = new Teams(); if (array_key_exists('id', $data) && $data['id'] > 0) { $teamId = $this->getTeamId($data['id']); } //assign user priviliges $data['modified'] = $date; $data['admin'] = array_key_exists('admin', $data) && $data['admin'] == '1' ? 1 : 0; $data['exports'] = array_key_exists('exports', $data) && $data['exports'] == 'on' ? 1 : 0; $data['can_delete'] = array_key_exists('can_delete', $data) && $data['can_delete'] == 'on' ? 1 : 0; //republish / register users if (array_key_exists('id', $data) && $data['id'] != "") { $query = $this->db->getQuery(true); $query->clear()->select("id")->from("#__users")->where("id=" . $data['id']); $this->db->setQuery($query); $id = $this->db->loadResult(); if ($id) { $data['id'] = $id; $data['published'] = 1; } } if (array_key_exists('team_id', $data) && $data['team_id'] == "") { unset($data['team_id']); } // Bind the form fields to the table if (!$row->bind($data)) { $this->setError($this->db->getErrorMsg()); return false; } // Make sure the record is valid if (!$row->check()) { $this->setError($this->db->getErrorMsg()); return false; } // Store the web link table to the database if (!$row->store()) { $this->setError($this->db->getErrorMsg()); return false; } if (array_key_exists('role_type', $data) && $data['role_type'] == "manager") { $teamModel = new Teams(); $teamName = array_key_exists('team_name', $data) ? $data['team_name'] : ""; $teamModel->createTeam($row->id, $teamName); } //if we are downgrading a users priviliges if (array_key_exists('manager_assignment', $data) && $data['manager_assignment'] != null && $data['manager_assignment'] != "") { $newTeamId = $this->getTeamId($data['manager_assignment']); $model->updateTeam($teamId, $newTeamId); } $row->id = array_key_exists('id', $data) && $data['id'] > 0 ? $data['id'] : $this->db->insertId(); $this->updateUserMap($row); //$this->app->triggerEvent('onAfterCRMUserSave', array(&$data)); return true; }