public static function getDynamicStyle() { //database $db = \Cobalt\Container::fetch('db'); $query = $db->getQuery(true); //query $query->select("b.*"); $query->from("#__branding AS b"); $query->where("assigned=1"); //return results $db->setQuery($query); $theme = $db->loadAssocList(); $theme = $theme[0]; //assign style declarations $style = ".google_map_center{background:" . $theme['table_header_text'] . ";border:3px solid " . $theme['table_header_row'] . ";}"; $style .= ".navbar-inner{background:" . $theme['header'] . " ;}"; $style .= ".navbar .nav > li > a:hover{background:" . $theme['tabs_hover'] . " ;}"; $style .= ".navbar .nav > li > a:hover{color:" . $theme['tabs_hover_text'] . " ;}"; $style .= ".table th{background:" . $theme['table_header_row'] . " ;}"; $style .= ".table th{color:" . $theme['table_header_text'] . " ;}"; $style .= ".table th a{color:" . $theme['table_header_text'] . " ;}"; $style .= ".table tr td a,a{color:" . $theme['link'] . " ;}"; $style .= ".table tr td a:hover,a:hover{color:" . $theme['link_hover'] . " ;}"; $style .= ".block-btn{border-left:1px solid " . $theme['block_btn_border'] . " ;}"; $style .= ".feature-btn{border-left:1px solid " . $theme['feature_btn_border'] . " ; border-right:1px solid " . $theme['feature_btn_border'] . " ;background:" . $theme['feature_btn_bg'] . ";}"; //return return $style; }
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 static function getTotalDocuments() { //db $db = \Cobalt\Container::fetch('db'); $query = $db->getQuery(true); //select $query->select("count(*)"); $query->from("#__documents AS d"); //filter depending on user access $role = UsersHelper::getRole(); $user_id = UsersHelper::getUserId(); $team_id = UsersHelper::getTeamId(); if ($role != 'exec') { if ($role == 'manager') { $query->join('inner', '#__users AS u ON d.owner_id = u.id'); $query->where('u.team_id=' . $team_id); } else { $query->where(array("d.owner_id=" . $user_id, 'd.shared=1'), 'OR'); } } //return count $db->setQuery($query); $result = $db->loadResult(); return $result; }
public function store() { $app = \Cobalt\Container::fetch('app'); //Load Tables $row = new MenuTable(); $data = $app->input->getRequest('post'); //date generation $date = date('Y-m-d H:i:s'); $data['modified'] = $date; //serialize menu items for storage $data['menu_items'] = serialize($data['menu_items']); // 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; }
public static function getActivity() { $db = \Cobalt\Container::fetch('db'); $query = $db->getQuery(true); $query->select('h.*, CONCAT(u.first_name," ", u.last_name) AS owner_name, c.name as company_name, CONCAT(p.first_name," ", p.last_name) AS person_name, d.name as deal_name, e.name as event_name, note_cat.name as notes_category_name, event_cat.name as events_category_name, old_event_cat.name as events_category_name_old, old_note_cat.name AS notes_category_name_old, doc.name AS document_name,status.name AS deal_status_name_old, status2.name AS deal_status_name,deal_source.name AS deal_source_name_old,deal_source_2.name AS deal_source_name, deal_stage.name AS deal_stage_name_old,deal_stage_2.name AS deal_stage_name,CONCAT(deal_owner.first_name," ",deal_owner.last_name) AS deal_owner_name_old, CONCAT(deal_owner_2.first_name," ",deal_owner_2.last_name) AS deal_owner_name '); $query->from('#__history AS h'); $query->leftJoin('#__users AS u ON u.id = h.user_id'); $query->leftJoin('#__companies AS c ON c.id = h.type_id AND h.type="company"'); $query->leftJoin('#__notes AS n ON n.id = h.type_id AND h.type="note"'); $query->leftJoin('#__deals AS d on d.id = h.type_id AND h.type="deal"'); $query->leftJoin('#__people AS p on p.id = h.type_id AND h.type="person"'); $query->leftJoin('#__goals AS g on g.id = h.type_id AND h.type="goal"'); $query->leftJoin('#__events AS e on e.id = h.type_id AND h.type="event"'); $query->leftJoin('#__reports AS r on r.id = h.type_id AND h.type="report"'); $query->leftJoin('#__documents AS doc ON doc.id = h.type_id AND h.type="document"'); $query->leftJoin('#__notes_categories as note_cat ON note_cat.id = h.new_value AND h.field="category_id" AND h.type="notes"'); $query->leftJoin('#__events_categories as event_cat ON event_cat.id = h.new_value AND h.field="category_id" AND h.type="events"'); $query->leftJoin('#__notes_categories as old_note_cat ON old_note_cat.id = h.old_value AND h.field="category_id" AND h.type="notes"'); $query->leftJoin('#__events_categories as old_event_cat ON old_event_cat.id = h.old_value AND h.field="category_id" AND h.type="events"'); $query->leftJoin("#__deal_status AS status ON status.id = h.old_value AND h.type='deal'"); $query->leftJoin("#__deal_status AS status2 ON status2.id = h.new_value AND h.type='deal'"); $query->leftJoin("#__sources AS deal_source ON deal_source.id = h.old_value AND h.type='deal'"); $query->leftJoin("#__sources AS deal_source_2 ON deal_source_2.id = h.new_value AND h.type='deal'"); $query->leftJoin("#__stages AS deal_stage ON deal_stage.id = h.old_value AND h.type='deal'"); $query->leftJoin("#__stages AS deal_stage_2 ON deal_stage_2.id = h.new_value AND h.type='deal'"); $query->leftJoin("#__users AS deal_owner ON deal_owner.id = h.old_value AND h.type='deal'"); $query->leftJoin("#__users AS deal_owner_2 ON deal_owner_2.id = h.new_value AND h.type='deal'"); $member_id = UsersHelper::getUserId(); $member_role = UsersHelper::getRole(); $team_id = UsersHelper::getTeamId(); if ($member_role != 'exec') { //manager filter if ($member_role == 'manager') { $query->where('u.team_id = ' . $team_id); } else { //basic user filter $query->where(array('h.user_id = ' . $member_id)); } } //TODO: Add assignees to the display (massive left join) $query->where('h.field!="assignee_id" AND h.field!="repeats"'); $query->order('h.date DESC'); if (self::$limit != null) { $query .= " LIMIT " . self::$limit; } else { $query .= " LIMIT 10"; } $db->setQuery($query); $activity = $db->loadObjectList(); return $activity; }
/** * Constructor */ public function __construct() { parent::__construct(); $app = \Cobalt\Container::fetch('app'); $this->_view = $this->app->input->get('view'); $this->_layout = str_replace('_filter', '', $this->app->input->get('layout')); $this->_user_id = $app->getUser()->get('id'); $this->export = $this->app->input->getInt('export'); }
/** * Method to render the view. * * @return string The rendered view. * * @since 1.0 * @throws \RuntimeException */ public function render() { $this->basepath = Container::fetch('app')->get('uri.base.host'); $this->knownLangs = Container::fetch('app')->getLanguage()->getKnownLanguages(); $this->defaultLang = Container::fetch('app')->getLanguage()->getDefault(); $this->phpOptions = $this->model->getPhpOptions(); $this->dboDrivers = $this->model->dboDrivers(); return parent::render(); }
public function populateState() { //get states $app = \Cobalt\Container::fetch('app'); $filter_order = $app->getUserStateFromRequest('Source.filter_order', 'filter_order', 's.name'); $filter_order_Dir = $app->getUserStateFromRequest('Source.filter_order_Dir', 'filter_order_Dir', 'asc'); //set states $this->state->set('Source.filter_order', $filter_order); $this->state->set('Source.filter_order_Dir', $filter_order_Dir); }
public function render() { $app = \Cobalt\Container::fetch('app'); //get user data and pass to view $this->user = $app->getUser(); $this->user_id = $this->user->get('id'); $this->user->getEmails(); //display return parent::render(); }
/** * Constructor */ public function __construct($userId = null) { parent::__construct(); $app = \Cobalt\Container::fetch('app'); $this->_view = $app->input->get('view'); $this->_layout = str_replace('_filter', '', $app->input->get('layout')); if ($userId) { $this->load($userId); } }
/** * Constructor * * @since 1.0 */ public function __construct() { $container = Container::getInstance(); $container->registerServiceProvider(new ApplicationServiceProvider($this))->registerServiceProvider(new ConfigServiceProvider())->registerServiceProvider(new DatabaseServiceProvider()); $this->setContainer($container); // Set error reporting based on config $errorReporting = (int) $container->get('config')->get('errorReporting', 0); error_reporting($errorReporting); parent::__construct(); }
public static function getTranscripts($roomId = null) { $app = \Cobalt\Container::fetch('app'); $roomId = $roomId ? $roomId : $app->input->get('room_id'); $db = \Cobalt\Container::fetch('db'); $query = $db->getQuery(true); $query->select("t.*,r.name AS room_name")->from("#__banter_transcripts AS t")->leftJoin("#__banter_rooms AS r ON r.id = t.room_id")->where("t.room_id=" . $roomId); $db->setQuery($query); $transcripts = $db->loadObjectList(); return $transcripts; }
public function store() { $app = \Cobalt\Container::fetch('app'); //Load Tables $row = new FormWizardTable(); $data = $app->input->getRequest('post'); $app = \Cobalt\Container::fetch('app'); $user = $app->getUser(); $userId = $user->get('id'); //date generation $date = date('Y-m-d H:i:s'); $data['modified'] = $date; $data['modified_by'] = $userId; if (!array_key_exists('id', $data)) { $data['created'] = $date; $data['created_by'] = $userId; } if (array_key_exists('fields', $data)) { $data['fields'] = serialize($data['fields']); } if (array_key_exists('html', $data)) { $data['html'] = $_POST['html']; } //TODO: This poses a problem if the user creates a form and copies HTML immediately on new page before saving // they could potentially have an existing ID and then have the wrong code in their copied HTML // This would be rare and only if multiple users are simultaneously adding custom forms... if (array_key_exists('temp_id', $data)) { $db = JFactory::getDBO(); $query = $db->getQuery(true); $query->select('COUNT(*) as existing, MAX(id) AS greatest')->from('#__formwizard')->where('id = ' . $data['temp_id']); $db->setQuery($query); $existing = $db->loadAssoc(); if ($existing['existing'] > 0) { $nextId = $existing['greatest'] + 1; $data['html'] = preg_replace('/name="form_id" value="(.*?)"/', 'name="form_id" value="' . $nextId . '"', $data['html']); } } // 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; }
/** * Title cell. * For the title and toolbar to be rendered correctly, * this title fucntion must be called before the starttable function and the toolbars icons * this is due to the nature of how the css has been used to postion the title in respect to the toolbar. * * @param string $title The title. * @param string $icon The space-separated names of the image. * * @return void * * @since 1.5 */ public static function title($title, $icon = 'generic.png') { // Strip the extension. $icons = explode(' ', $icon); foreach ($icons as &$icon) { $icon = 'icon-48-' . preg_replace('#\\.[^.]*$#', '', $icon); } $html = '<div class="pagetitle ' . htmlspecialchars(implode(' ', $icons)) . '"><h2>' . $title . '</h2></div>'; $app = \Cobalt\Container::fetch('app'); $app->JComponentTitle = $html; }
public function populateState() { //get states $app = \Cobalt\Container::fetch('app'); $filter_order = $app->getUserStateFromRequest('Categories.filter_order', 'filter_order', 'c.name'); $filter_order_Dir = $app->getUserStateFromRequest('Categories.filter_order_Dir', 'filter_order_Dir', 'asc'); $state = new Registry(); //set states $state->set('Categories.filter_order', $filter_order); $state->set('Categories.filter_order_Dir', $filter_order_Dir); $this->setState($state); }
public function render($tpl = null) { //authenticate the current user to make sure they are an admin UsersHelper::authenticateAdmin(); //application $app = \Cobalt\Container::fetch('app'); //display title $document = JFactory::getDocument(); //load model $layout = $this->getLayout(); $model = new UsersModel(); $model->set("_layout", $layout); //add toolbar buttons to manage users if ($layout == 'default') { $this->toolbar = new Toolbar(); $this->toolbar->addNew(); $this->toolbar->addDeleteRow(); //get users $users = $model->getUsers(); // Initialise variables. $this->state = $model->getState(); //assign refs $this->users = $users; $this->listOrder = $this->state->get('Users.filter_order'); $this->listDirn = $this->state->get('Users.filter_order_Dir'); } elseif ($this->getLayout() == 'edit') { $model = new UserModel(); $model->set("_layout", $layout); $this->toolbar = new Toolbar(); $this->toolbar->save(); $this->toolbar->cancel(); //get id $id = $app->input->getInt('id', null); //plugins //$app->triggerEvent('onBeforeCRMUserEdit', array(&$id)); //get user $this->user = $model->getUser($id); //view data $roles = DropdownHelper::getMemberRoles(); $teamId = UsersHelper::getTeamId($id); $teams = UsersHelper::getTeams($teamId); $managers = DropdownHelper::getManagers($id); $this->member_roles = $roles; $this->teams = $teams; $this->managers = $managers; } /** Menu Links **/ $menu = MenuHelper::getMenuModules(); $this->menu = $menu; //display return parent::render(); }
public function register(Container $container) { /** @var $config Registry */ $config = $container->resolve('config'); if ($config->get('debug', false)) { $whoops = new Run(); $handler = new PrettyPageHandler(); $editor = $config->get('debugEditor'); if ($editor == 'pstorm') { $handler->setEditor(function ($file, $line) { return "pstorm://{$file}:{$line}"; }); } else { $handler->setEditor($editor); } $whoops->pushHandler($handler); $whoops->register(); $container->bind('whoops', function () use($whoops) { return $whoops; }); } }
public function render($tpl = null) { $app = \Cobalt\Container::fetch('app'); $doc = $app->getDocument(); $doc->addScript(JURI::base() . 'src/Cobalt/media/js/import_manager.js'); if (count($_FILES) > 0) { $model = new ImportModel(); foreach ($_FILES as $file) { $import_data = $model->readCSVFile($file['tmp_name']); } $this->headers = $import_data['headers']; unset($import_data['headers']); $this->import_data = $import_data; if (count($import_data) > 500) { switch ($app->input->get('import_type')) { case "company": $view = "companies"; $import_model = "company"; break; case "people": $view = "people"; $import_model = "people"; break; case "deals": $view = "deals"; $import_model = "deal"; break; } if ($model->importCSVData($import_data, $import_model)) { $success = "SUCCESSFULLY"; } else { $success = "UNSUCCESSFULLY"; $view = "import&import_type=" . $app->input->get('import_type'); } $msg = TextHelper::_('COBALT_' . $success . '_IMPORTED_ITEMS'); $app->redirect(RouteHelper::_('index.php?view=' . $view), $msg); } $doc->addScriptDeclaration('import_length=' . count($import_data) . ';'); } $import_type = $app->input->get('import_type'); $import_header = ucwords(TextHelper::_('COBALT_IMPORT_' . $import_type)); $this->import_type = $import_type; $this->import_header = $import_header; if ($this->getLayout() == 'default') { $this->setLayout('import'); } //display return parent::render(); }
public static function getNamingConventions() { $db = \Cobalt\Container::fetch('db'); $query = $db->getQuery(true); $query->select("lang_deal,lang_person,lang_company,lang_contact,lang_lead,lang_task,lang_event,lang_goal")->from("#__config")->where("id=1"); $db->setQuery($query); $result = $db->loadObject(); $names = array(); if (count($result) > 0) { foreach ($result as $key => $value) { $names[$key] = $value; $names[self::pluralize($key)] = self::pluralize($value); } } return $names; }
public static function getCategories() { //grab db $db = \Cobalt\Container::fetch('db'); //generate query $query = $db->getQuery(true); $query->select("name,id"); $query->from("#__notes_categories"); //return results $db->setQuery($query); $results = $db->loadAssocList(); $categories = array(); foreach ($results as $key => $category) { $categories[$category['id']] = $category['name']; } return $categories; }
public static function getCategories($appendLanguage = FALSE) { //grab db $db = \Cobalt\Container::fetch('db'); //generate query $query = $db->getQuery(true); $query->select("name,id"); $query->from("#__events_categories"); //return results $db->setQuery($query); $results = $db->loadAssocList(); $categories = array(); foreach ($results as $key => $category) { $categories[$category['id']] = $appendLanguage ? TextHelper::_('COBALT_OF_TYPE') . ' ' . $category['name'] : $category['name']; } return $categories; }
public function __construct(DatabaseDriver $db = null) { if (is_null($db)) { $db = Container::fetch('db'); } parent::__construct($db); $this->app = Container::fetch('app'); $ids = $this->app->input->get("cids", null, 'array'); $id = $this->app->input->getInt("id"); if ($id && $id > 0) { $this->id = $id; } elseif (count($ids) == 1) { $this->id = $ids[0]; } else { $this->id = $ids; } }
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 static function getSelectedColumnFilters() { //get the user session data $db = \Cobalt\Container::fetch('db'); $query = $db->getQuery(true); $query->select("people_columns"); $query->from("#__users"); $query->where("id=" . UsersHelper::getUserId()); $db->setQuery($query); $results = $db->loadResult(); //unserialize columns $columns = unserialize($results); if (is_array($columns)) { return $columns; } else { //if it is empty then load a default set return PeopleHelper::getDefaultColumnFilters(); } }
/** * Method to store a record * @param $_POST data * @return boolean True on success */ public function store() { $app = \Cobalt\Container::fetch('app'); //Load Tables $row = new GoalTable(); $oldRow = new GoalTable(); $data = $app->input->getArray(); //date generation $date = DateHelper::formatDBDate(date('Y-m-d H:i:s')); if (!array_key_exists('id', $data)) { $data['created'] = $date; $status = "created"; } else { $row->load($data['id']); $oldRow->load($data['id']); $status = "updated"; } //assign checkboxes if (array_key_exists('leaderboard', $data)) { $data['leaderboard'] = 1; } else { $data['leaderboard'] = 0; } //assign owner id $data['owner_id'] = UsersHelper::getUserId(); // 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; } ActivityHelper::saveActivity($oldRow, $row, 'goal', $status); return true; }
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; }
/** * Method to store a record * * @return boolean True on success */ public function store() { $app = \Cobalt\Container::fetch('app'); //Load Tables $row = new ConversationTable(); $oldRow = new ConversationTable(); $data = $app->input->getRequest('post'); //date generation $date = DateHelper::formatDBDate(date('Y-m-d H:i:s')); if (!array_key_exists('id', $data)) { $data['created'] = $date; $status = "created"; } else { $row->load($data['id']); $oldRow->load($data['id']); $status = "updated"; } $data['modified'] = $date; $data['author'] = UsersHelper::getUserId(); // 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; } $id = array_key_exists('id', $data) ? $data['id'] : $this->db->insertId(); ActivityHelper::saveActivity($oldRow, $row, 'conversation', $status); return $id; }
/** * Object constructor to set table and key fields. In most cases this will * be overridden by child classes to explicitly set the table and key fields * for a particular database table. * * @param string $table Name of the table to model. * @param mixed $keys Name of the primary key field in the table or array of field names that compose the primary key. * @param DatabaseDriver $db DatabaseDriver object. * * @since 1.0 */ public function __construct($table = null, $keys = null, DatabaseDriver $db = null) { // Set internal variables. if (is_null($this->tableName)) { $this->tableName = $table; } $this->db = $db ?: Container::fetch('db'); $this->tableFields = new \stdClass(); // Set the key to be an array. if (is_string($keys) && $keys) { $this->tableKeys = array($keys); } elseif (is_object($keys) && $keys) { $this->tableKeys = (array) $keys; } $this->autoIncrement = count($this->tableKeys) == 1 ? true : false; // Initialise the table properties. $fields = $this->getFields(); if ($fields) { foreach ($fields as $name => $v) { // Add the field if it is not already present. $this->tableFields->{$name} = null; } } }
public function upload() { //this is the name of the field in the html form, filedata is the default name for swfupload //so we will leave it as that $fieldName = 'document'; //any errors the server registered on uploading $fileError = $_FILES[$fieldName]['error']; if ($fileError > 0) { switch ($fileError) { case 1: echo TextHelper::_('FILE TO LARGE THAN PHP INI ALLOWS'); return; case 2: echo TextHelper::_('FILE TO LARGE THAN HTML FORM ALLOWS'); return; case 3: echo TextHelper::_('ERROR PARTIAL UPLOAD'); return; case 4: echo TextHelper::_('ERROR NO FILE'); return; } } //check for filesize $fileSize = $_FILES[$fieldName]['size']; if ($fileSize > 2000000) { echo TextHelper::_('FILE BIGGER THAN 2MB'); } //check the file extension is ok $fileName = $_FILES[$fieldName]['name']; $uploadedFileNameParts = explode('.', $fileName); $uploadedFileExtension = array_pop($uploadedFileNameParts); $validFileExts = explode(',', 'jpeg,jpg,png,gif,pdf,doc,docx,odt,rtf,ppt,xls,txt'); //assume the extension is false until we know its ok $extOk = false; //go through every ok extension, if the ok extension matches the file extension (case insensitive) //then the file extension is ok foreach ($validFileExts as $key => $value) { if (preg_match("/{$value}/i", $uploadedFileExtension)) { $extOk = true; } } if ($extOk == false) { echo TextHelper::_('INVALID EXTENSION'); return; } //the name of the file in PHP's temp directory that we are going to move to our folder $fileTemp = $_FILES[$fieldName]['tmp_name']; //for security purposes, we will also do a getimagesize on the temp file (before we have moved it //to the folder) to check the MIME type of the file, and whether it has a width and height $imageinfo = getimagesize($fileTemp); //lose any special characters in the filename $fileName = ereg_replace("[^A-Za-z0-9.]", "-", $fileName); $hash = md5($fileName) . "." . $uploadedFileExtension; //always use constants when making file paths, to avoid the possibilty of remote file inclusion $uploadPath = JPATH_SITE . '/uploads/' . $hash; $app = \Cobalt\Container::fetch('app'); if (!File::upload($fileTemp, $uploadPath)) { $msg = TextHelper::_('COBALT_DOC_UPLOAD_FAIL'); $app->redirect('index.php?view=admindocuments', $msg); } else { //update the database //date generation $date = date('Y-m-d H:i:s'); $data = array('name' => $fileName, 'filename' => $hash, 'filetype' => $uploadedFileExtension, 'size' => $fileSize / 1024, 'created' => $date, 'shared' => 1, 'is_image' => is_array(getimagesize($uploadPath)) ? true : false); $model = new static(); $session = JFactory::getSession(); if ($model->store($data)) { $msg = TextHelper::_('COM_CRMERY_DOC_UPLOAD_SUCCESS'); $app->redirect('index.php?view=admindocuments&layout=upload_success&format=raw', $msg); $session->set("upload_success", true); } else { $msg = TextHelper::_('COM_CRMERY_DOC_UPLOAD_FAIL'); $app->redirect('index.php?view=admindocuments&layout=upload_success&format=raw', $msg); $session->set("upload_success", false); } } }
/** * Populate user state requests */ public function populateState() { //get states $app = \Cobalt\Container::fetch('app'); //determine view so we set correct states $view = $this->view; $layout = $this->layout; // if ( $view == "events" && ( $layout == "default" || $layout == "list" || $layout == null ) ) { // Get pagination request variables $limit = $app->getUserStateFromRequest("Event." . $view . '_' . $layout . '_limit', 'limit', 10); $limitstart = $app->getUserStateFromRequest("Event." . $view . '_' . $layout . '_limitstart', 'limitstart', 0); // In case limit has been changed, adjust it $limitstart = $limit != 0 ? floor($limitstart / $limit) * $limit : 0; $state = new Registry(); $state->set("Event." . $view . '_limit', $limit); $state->set("Event." . $view . '_limitstart', $limitstart); //set default filter states for reports $filterOrder = "CASE e.type WHEN 'event' THEN e.start_time WHEN 'task' THEN e.due_date ELSE e.due_date END"; $filterOrderDir = "ASC"; $filter_order = $app->getUserStateFromRequest('Event.' . $view . '_' . $layout . '_filter_order', 'filter_order', $filterOrder); $filter_order_Dir = $app->getUserStateFromRequest('Event.' . $view . '_' . $layout . '_filter_order_Dir', 'filter_order_Dir', $filterOrderDir); $status_filter = $app->getUserStateFromRequest('Event.' . $view . '_' . $layout . '_status', 'status', 0); $type_filter = $app->getUserStateFromRequest('Event.' . $view . '_' . $layout . '_type', 'type', 'all'); $category_filter = $app->getUserStateFromRequest('Event.' . $view . '_' . $layout . '_category', 'category', 'any'); $due_date_filter = $app->getUserStateFromRequest('Event.' . $view . '_' . $layout . '_due_date', 'due_date', 'any'); $association_type_filter = $app->getUserStateFromRequest('Event.' . $view . '_' . $layout . '_association_type', 'association_type', 'any'); $assignee_id_filter = $app->getUserStateFromRequest('Event.' . $view . '_' . $layout . '_assignee_id', 'assignee_id', UsersHelper::getUserId()); $assignee_filter_type = $app->getUserStateFromRequest('Event.' . $view . '_' . $layout . '_assignee_filter_type', 'assignee_filter_type', 'individual'); //set states for reports $state->set('Event.' . $view . '_' . $layout . '_filter_order', $filter_order); $state->set('Event.' . $view . '_' . $layout . '_filter_order_Dir', $filter_order_Dir); $state->set('Event.' . $view . '_' . $layout . '_status', $status_filter); $state->set('Event.' . $view . '_' . $layout . '_type', $type_filter); $state->set('Event.' . $view . '_' . $layout . '_category', $category_filter); $state->set('Event.' . $view . '_' . $layout . '_due_date', $due_date_filter); $state->set('Event.' . $view . '_' . $layout . '_association_type', $association_type_filter); $state->set('Event.' . $view . '_' . $layout . '_assignee_id', $assignee_id_filter); $state->set('Event.' . $view . '_' . $layout . '_assignee_filter_type', $assignee_filter_type); $this->setState($state); //} }