Exemple #1
0
 public function render($tpl = null)
 {
     //get model and retrieve info
     $model = new EventModel();
     if (TemplateHelper::isMobile()) {
         $model->set('current_events', true);
     }
     $events = $model->getEvents();
     $eventDock = ViewHelper::getView('events', 'dashboard_event_dock', 'phtml', array('events' => $events));
     $dealModel = new DealModel();
     $dealModel->set('_view', 'dashboard');
     $dealModel->set('recent', true);
     $dealModel->set('archived', 0);
     $recentDeals = $dealModel->getDeals();
     $doc = JFactory::getDocument();
     //get data for sales graphs
     $model = new GraphsModel();
     $graph_data = $model->getGraphData();
     $activityHelper = new ActivityHelper();
     $activity = $activityHelper->getActivity();
     //assign results to view
     $this->eventDock = $eventDock;
     $this->graph_data = $graph_data;
     $this->recentDeals = $recentDeals;
     $this->activity = $activity;
     $json = TRUE;
     $peopleModel = new PeopleModel();
     if (TemplateHelper::isMobile()) {
         $dealModel->set('recent', false);
         $totalDeals = $dealModel->getTotal();
         $peopleModel->set('type', 'leads');
         $totalLeads = $peopleModel->getTotal();
         $peopleModel->set('type', 'not_leads');
         $totalContacts = $peopleModel->getTotal();
         $companyModel = new CompanyModel();
         $totalCompanies = $companyModel->getTotal();
         $user = UsersHelper::getLoggedInUser();
         $this->first_name = $user->first_name;
         $this->numEvents = count($events);
         $this->numDeals = $totalDeals;
         $this->numLeads = $totalLeads;
         $this->numContacts = $totalContacts;
         $this->numCompanies = $totalCompanies;
     }
     $peopleNames = $peopleModel->getPeopleNames($json);
     $doc->addScriptDeclaration("var people_names=" . $peopleNames . ";");
     $dealModel = new DealModel();
     $dealNames = $dealModel->getDealNames($json);
     $doc->addScriptDeclaration("var deal_names=" . $dealNames . ";");
     /** get latest activities **/
     $this->latest_activities = ViewHelper::getView('dashboard', 'latest_activities', 'phtml');
     $this->latest_activities->activity = $activity;
     $activityHelper = new ActivityHelper();
     $activity = $activityHelper->getActivity();
     //display
     return parent::render();
 }
Exemple #2
0
 /**
  * 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;
 }
Exemple #3
0
 /**
  * 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;
 }
Exemple #4
0
 /**
  * Postpone events
  * @param [int] $days
  */
 public function postponeEvent($days = null, $event_id = null)
 {
     $app = \Cobalt\Container::fetch('app');
     $event_id = $event_id == null ? $app->input->get('event_id') : $event_id;
     $days = $days == null ? $app->input->get("days") : $days;
     $db = JFactory::getDBO();
     $query = $db->getQuery(true);
     $query->select("e.type,e.due_date,e.start_time,e.end_time")->from("#__events AS e")->where("e.id=" . $event_id);
     $db->setQuery($query);
     $dates = $db->loadObjectList();
     //Load Tables
     $oldRow = new EventTable();
     $oldRow->load($event_id);
     if (count($dates) > 0) {
         foreach ($dates as $date) {
             $query->clear();
             $query->update('#__events');
             if ($date->type == "task") {
                 $due_date = date("Y-m-d H:i:s", strtotime(date("Y-m-d H:i:s", strtotime($date->due_date)) . "+" . $days . " days"));
                 $query->set(array("due_date='" . $due_date . "'"));
             } else {
                 $start_time = date("Y-m-d H:i:s", strtotime(date("Y-m-d H:i:s", strtotime($date->start_time)) . "+" . $days . " days"));
                 $end_time = date("Y-m-d H:i:s", strtotime(date("Y-m-d H:i:s", strtotime($date->end_time)) . "+" . $days . " days"));
                 $query->set(array("start_time='" . $start_time . "'", "end_time='" . $end_time . "'"));
             }
             $query->where("id=" . $event_id);
             $db->setQuery($query);
             $db->execute();
         }
     }
     $row = new EventTable();
     $row->load($event_id);
     $status = "postponed";
     ActivityHelper::saveActivity($oldRow, $row, 'event', $status);
 }
Exemple #5
0
 /**
  * Method to store a record
  *
  * @return boolean True on success
  */
 public function store($data = null, $returnRow = false)
 {
     //Load Tables
     $row = new DealTable();
     $oldRow = new DealTable();
     if ($data == null) {
         $data = $this->app->input->post->getArray();
     }
     //date generation
     $date = DateHelper::formatDBDate(date('Y-m-d H:i:s'));
     //assign the creation date
     if (!array_key_exists('id', $data) || array_key_exists('id', $data) && $data['id'] <= 0) {
         $data['created'] = $date;
         $status = "created";
         //assign the owner id
         $data['owner_id'] = array_key_exists('owner_id', $data) ? $data['owner_id'] : $this->app->getUser()->get('id');
     } else {
         $row->load($data['id']);
         $oldRow->load($data['id']);
         $status = "updated";
     }
     //update our modified date
     $data['modified'] = $date;
     //generate custom field string
     $customArray = array();
     foreach ($data as $name => $value) {
         if (strstr($name, 'custom_') && !strstr($name, '_input') && !strstr($name, "_hidden")) {
             $id = str_replace('custom_', '', $name);
             $customArray[] = array('custom_field_id' => $id, 'custom_field_value' => $value);
             unset($data[$name]);
         }
     }
     if (array_key_exists('expected_close', $data)) {
         if (strpos($data['expected_close'], '/')) {
             $dateParts = explode('/', $data['expected_close']);
             $expected_close = new \JDate(sprintf('%s-%s-%s 00:00:00', $dateParts[1], $dateParts[0], '20' . $dateParts[2]));
         } else {
             $expected_close = new \JDate($data['expected_close']);
         }
         $data['expected_close'] = $expected_close->toSql();
     }
     if (array_key_exists('company_name', $data) && $data['company_name'] != "" || array_key_exists('company', $data) && $data['company'] != "") {
         $company_name = array_key_exists('company_name', $data) ? $data['company_name'] : $data['company'];
         $companyModel = new Company();
         $existingCompany = $companyModel->checkCompanyName($company_name);
         if ($existingCompany == "") {
             $cdata = array();
             $cdata['name'] = $company_name;
             $data['company_id'] = $companyModel->store($cdata);
         } else {
             $data['company_id'] = $existingCompany;
         }
     }
     if (array_key_exists('company_id', $data) && is_array($data['company_id'])) {
         $company_name = $data['company_id']['value'];
         $companyModel = new Company();
         $existingCompany = $companyModel->checkCompanyName($company_name);
         if ($existingCompany == "") {
             $cdata = array();
             $cdata['name'] = $company_name;
             $data['company_id'] = $companyModel->store($cdata)->id;
         } else {
             $data['company_id'] = $existingCompany;
         }
     }
     //deal was closed
     $closedStages = $this->getClosedStages();
     if (array_key_exists('stage_id', $data) && in_array($data['stage_id'], $closedStages)) {
         $data['actual_close'] = $date;
     }
     /** check for and automatically associate and create primary contacts or people **/
     if (array_key_exists('person_name', $data) && $data['person_name'] != "") {
         $peopleModel = new People();
         $existingPerson = $peopleModel->checkPersonName($data['person_name']);
         if ($existingPerson == "") {
             $pdata = array();
             $name = explode(" ", $data['person_name']);
             $pdata['first_name'] = $name[0];
             $pdata['last_name'] = array_key_exists(1, $name) ? $name[1] : "";
             if (array_key_exists('company_id', $data)) {
                 $pdata['company_id'] = $data['company_id'];
             }
             $data['person_id'] = $peopleModel->store($pdata);
         } else {
             $data['person_id'] = $existingPerson;
         }
     }
     if (array_key_exists('primary_contact_name', $data) && $data['primary_contact_name'] != "") {
         $peopleModel = new People();
         $existingPerson = $peopleModel->checkPersonName($data['primary_contact_name']);
         if ($existingPerson == "") {
             $pdata = array();
             $name = explode(" ", $data['primary_contact_name']);
             $pdata['first_name'] = $name[0];
             $pdata['last_name'] = array_key_exists(1, $name) ? $name[1] : "";
             if (array_key_exists('company_id', $data)) {
                 $pdata['company_id'] = $data['company_id'];
             }
             $data['primary_contact_id'] = $peopleModel->store($pdata);
         } else {
             $data['primary_contact_id'] = $existingPerson;
         }
     }
     // Bind the form fields to the table
     if (!$row->bind($data)) {
         $this->setError($this->db->getErrorMsg());
         return false;
     }
     //$this->app->triggerEvent('onBeforeDealSave', array(&$row));
     // 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;
     }
     $deal_id = array_key_exists('id', $data) && $data['id'] > 0 ? $data['id'] : $row->id;
     ActivityHelper::saveActivity($oldRow, $row, 'deal', $status);
     //if we receive no custom post data do not modify the custom fields
     if (count($customArray) > 0) {
         CobaltHelper::storeCustomCf($deal_id, $customArray, 'deal');
     }
     if (!empty($data['primary_contact_id']) || !empty($data['person_id'])) {
         $contactId = array_key_exists('primary_contact_id', $data) ? $data['primary_contact_id'] : $data['person_id'];
         $this->storeContact($deal_id, $contactId);
     }
     $closed_stages = DealHelper::getClosedStages();
     $row->closed = in_array($row->stage_id, $closed_stages) ? TRUE : FALSE;
     $row->actual_close_formatted = isset($row->actual_close) ? DateHelper::formatDate($row->actual_close) : DateHelper::formatDate(date("Y-m-d"));
     $row->expected_close_formatted = isset($row->expected_close) ? DateHelper::formatDate($row->expected_close) : DateHelper::formatDate(date("Y-m-d"));
     //$this->app->triggerEvent('onAfterDealSave', array(&$row));
     //return success
     if ($returnRow) {
         return $row;
     } else {
         return $deal_id;
     }
 }
Exemple #6
0
 /**
  * Method to store a record
  *
  * @return boolean True on success
  */
 public function store($data = null)
 {
     $app = \Cobalt\Container::fetch('app');
     //Load Tables
     $row = new NoteTable();
     $oldRow = new NoteTable();
     if ($data == null) {
         $data = $app->input->getArray(array('note' => 'string', 'deal_id' => 'int', 'person_id' => 'int', 'name' => 'string', 'category_id' => 'int', 'company_id' => 'int', 'note_id' => 'int', 'event_id' => 'int'));
     }
     if (array_key_exists('note_id', $data)) {
         $data['id'] = $data['note_id'];
     }
     if (array_key_exists('is_email', $data)) {
         $model = new Mail();
         $email = $model->getEmail($data['email_id']);
         $data['note'] = $email;
     }
     /** check for and automatically associate and create primary contacts or people **/
     if (array_key_exists('person_name', $data) && $data['person_name'] != "") {
         $peopleModel = new People();
         $existingPerson = $peopleModel->checkPersonName($data['person_name']);
         if ($existingPerson == "") {
             $pdata = array();
             $name = explode(" ", $data['person_name']);
             $pdata['first_name'] = array_key_exists(0, $name) ? $name[0] : "";
             $pdata['last_name'] = array_key_exists(1, $name) ? $name[1] : "";
             $data['person_id'] = $peopleModel->store($pdata);
         } else {
             $data['person_id'] = $existingPerson;
         }
     }
     /** check for and automatically associate and create deals **/
     if (array_key_exists('deal_name', $data) && $data['deal_name'] != "" && (!array_key_exists('deal_id', $data) || empty($data['deal_id']) || $data['deal_id'] == 0)) {
         $dealModel = new Deal();
         $existingDeal = $dealModel->checkDealName($data['deal_name']);
         if ($existingDeal == "") {
             $pdata = array();
             $pdata['name'] = $data['deal_name'];
             $data['deal_id'] = $dealModel->store($pdata);
         } else {
             $data['deal_id'] = $existingDeal;
         }
     }
     //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['owner_id'] = UsersHelper::getUserId();
     // Bind the form fields to the table
     if (!$row->bind($data)) {
         $this->setError($this->db->getErrorMsg());
         return false;
     }
     //$app->triggerEvent('onBeforeNoteSave', array(&$row));
     // 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('id', $data) && intval($data['id'])) {
         $id = $data['id'];
     } else {
         $id = $this->db->insertId();
     }
     ActivityHelper::saveActivity($oldRow, $row, 'note', $status);
     //Store email attachments
     if (array_key_exists('is_email', $data)) {
         $model = new CobaltModelMail();
         $model->storeAttachments($data['email_id'], $data['person_id']);
     }
     //$app->triggerEvent('onAfterNoteSave', array(&$row));
     return $id;
 }
Exemple #7
0
 /**
  * Method to run the application routines.
  *
  * @return  void
  *
  * @since   1.0
  */
 public function doExecute()
 {
     // Register the template to the config
     $template = $this->getTemplate(true);
     $this->set('theme', $template->template);
     $this->set('themeFile', $this->input->get('tmpl', 'index') . '.php');
     // Set metadata
     $this->document->setTitle('Cobalt');
     // Start the output buffer
     ob_start();
     // Install check
     if (!file_exists(JPATH_CONFIGURATION . '/configuration.php') || filesize(JPATH_CONFIGURATION . '/configuration.php') < 10) {
         // Redirect to the installer if we aren't there
         if (strpos($this->get('uri.route'), 'install') === false && $this->input->getString('task') != 'install') {
             ob_end_flush();
             $this->redirect(RouteHelper::_('index.php?view=install'));
         }
         // Build a session object to push into the DI container
         $session = new Session(new MockFileSessionStorage());
         $this->getContainer()->set('session', $session);
         // Fetch the controller
         $controllerObj = $this->getRouter()->getController($this->get('uri.route'));
         // Perform the Request task
         $controllerObj->execute();
     } elseif (file_exists(JPATH_CONFIGURATION . '/configuration.php') && filesize(JPATH_CONFIGURATION . '/configuration.php') > 10 && strpos($this->get('uri.route'), 'install') !== false) {
         $this->redirect(RouteHelper::_('index.php'));
     } else {
         // Finish bootstrapping the application now
         $this->getContainer()->registerServiceProvider(new Provider\ConfigServiceProvider())->registerServiceProvider(new Provider\DatabaseServiceProvider())->registerServiceProvider(new Provider\SessionServiceProvider());
         $this->loadConfiguration();
         // Load Language
         UsersHelper::loadLanguage();
         // Set site timezone
         $tz = DateHelper::getSiteTimezone();
         // Get user object
         $user = $this->getUser();
         // Fetch the controller
         $controllerObj = $this->getRouter()->getController($this->get('uri.route'));
         // Require specific controller if requested
         $controller = $this->input->get('controller', 'default');
         // Load user toolbar
         $format = $this->input->get('format');
         $overrides = array('ajax', 'mail', 'login');
         $loggedIn = $user->isAuthenticated();
         if ($loggedIn && $format !== 'raw' && !in_array($controller, $overrides)) {
             ActivityHelper::saveUserLoginHistory();
             // Set a default view if none exists
             $this->input->def('view', 'dashboard');
             // Grab document instance
             $document = $this->getDocument();
             // Start component div wrapper
             if (!in_array($this->input->get('view'), array('print'))) {
                 TemplateHelper::loadToolbar();
             }
             TemplateHelper::startCompWrap();
             // Load javascript language
             TemplateHelper::loadJavascriptLanguage();
             TemplateHelper::showMessages();
         }
         if (!$loggedIn && !$controllerObj instanceof \Cobalt\Controller\Login) {
             $this->redirect(RouteHelper::_('index.php?view=login'));
         }
         // Fullscreen detection
         if (UsersHelper::isFullscreen()) {
             $this->input->set('tmpl', 'component');
         }
         // Perform the Request task
         $controllerObj->execute();
         // End componenet wrapper
         if ($user !== false && $format !== 'raw') {
             TemplateHelper::endCompWrap();
         }
     }
     $contents = ob_get_clean();
     if ($this->input->get('format', 'html') === 'raw') {
         $this->setBody($contents);
     } else {
         $this->document->setBuffer($contents, 'cobalt');
         $this->setBody($this->document->render(false, (array) $template));
     }
 }
Exemple #8
0
 /**
  * Method to store a record
  *
  * @return boolean True on success
  */
 public function store($data = null)
 {
     //Load Tables
     $row = new PeopleTable();
     $oldRow = new PeopleTable();
     if ($data == null) {
         $data = $this->app->input->getArray(array('id' => 'int', 'first_name' => 'string', 'last_name' => 'string', 'company' => 'string', 'company_id' => 'int', 'position' => 'string', 'phone' => 'string', 'email' => 'email', 'source_id' => 'int', 'status_id' => 'int', 'deal_id' => 'int', 'type' => 'string', 'home_address_1' => 'string', 'home_address_2' => 'string', 'home_city' => 'string', 'home_state' => 'string', 'home_zip' => 'string', 'home_country' => 'string', 'work_address_1' => 'string', 'work_address_2' => 'string', 'work_city' => 'string', 'work_country' => 'string', 'work_state' => 'string', 'work_zip' => 'string', 'assignee_name' => 'string', 'assignee_id' => 'int', 'assignment_note' => 'string', 'mobile_phone' => 'string', 'home_email' => 'email', 'other_email' => 'email', 'home_phone' => 'string', 'fax' => 'string', 'website' => 'string', 'facebook_url' => 'string', 'twitter_user' => 'string', 'linkedin_url' => 'string', 'aim' => 'string'));
     }
     //date generation
     $date = DateHelper::formatDBDate(date('Y-m-d H:i:s'));
     if (!array_key_exists('id', $data) || array_key_exists('id', $data) && $data['id'] <= 0) {
         $data['created'] = $date;
         $data['owner_id'] = array_key_exists('owner_id', $data) ? $data['owner_id'] : UsersHelper::getUserId();
         $status = "created";
     } else {
         $row->load($data['id']);
         $oldRow->load($data['id']);
         $status = "updated";
     }
     $data['modified'] = $date;
     //generate custom field string
     $customArray = array();
     foreach ($data as $name => $value) {
         if (strstr($name, 'custom_') && !strstr($name, '_input') && !strstr($name, "_hidden")) {
             $id = str_replace('custom_', '', $name);
             $customArray[] = array('custom_field_id' => $id, 'custom_field_value' => $value);
             unset($data[$name]);
         }
     }
     if (array_key_exists('company_name', $data) && $data['company_name'] != "" || array_key_exists('company', $data) && $data['company'] != "") {
         $company_name = array_key_exists('company_name', $data) ? $data['company_name'] : $data['company'];
         $companyModel = new Company();
         $existingCompany = $companyModel->checkCompanyName($company_name);
         if ($existingCompany == "") {
             $cdata = array();
             $cdata['name'] = $company_name;
             $data['company_id'] = $companyModel->store($cdata);
         } else {
             $data['company_id'] = $existingCompany;
         }
     }
     if (array_key_exists('company_id', $data) && is_array($data['company_id'])) {
         $company_name = $data['company_id']['value'];
         $companyModel = new Company();
         $existingCompany = $companyModel->checkCompanyName($company_name);
         if ($existingCompany == "") {
             $cdata = array();
             $cdata['name'] = $company_name;
             $data['company_id'] = $companyModel->store($cdata)->id;
         } else {
             $data['company_id'] = $existingCompany;
         }
     }
     /** retrieving joomla user id **/
     if (array_key_exists('email', $data)) {
         $data['id'] = self::associateJoomlaUser($data['email']);
     }
     // Bind the form fields to the table
     if (!$row->bind($data)) {
         $this->setError($this->db->getErrorMsg());
         return false;
     }
     $app = \Cobalt\Container::fetch('app');
     //$app->triggerEvent('onBeforePersonSave', array(&$row));
     // 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;
     }
     $person_id = isset($data['id']) ? $data['id'] : $this->db->insertId();
     /** Updating the joomla user **/
     if (array_key_exists('id', $data) && intval($data['id']) && array_key_exists('email', $data) && array_key_exists('first_name', $data) && array_key_exists('last_name', $data)) {
         self::updateJoomlaUser($data);
     }
     ActivityHelper::saveActivity($oldRow, $row, 'person', $status);
     //if we receive no custom post data do not modify the custom fields
     if (count($customArray) > 0) {
         CobaltHelper::storeCustomCf($person_id, $customArray, 'people');
     }
     //bind to cf tables for deal & person association
     if (isset($data['deal_id']) && $data['deal_id']) {
         $deal = array('association_id = ' . $data['deal_id'], 'association_type="deal"', 'person_id = ' . $row->id, "created = '{$date}'");
         if (!$this->dealsPeople($deal)) {
             return false;
         }
     }
     //Pass Status to plugin & form ID if available
     $row->status = $status;
     if (isset($data) && is_array($data) && array_key_exists('form_id', $data)) {
         $row->form_id = $data['form_id'];
     } else {
         $row->form_id = '';
     }
     //$app->triggerEvent('onAfterPersonSave', array(&$row));
     return $person_id;
 }
Exemple #9
0
 /**
  * Method to store a record
  *
  * @return boolean True on success
  */
 public function store($data = null)
 {
     $app = \Cobalt\Container::fetch('app');
     //Load Tables
     $row = new CompanyTable();
     $oldRow = new CompanyTable();
     if ($data == null) {
         $data = $this->app->input->post->getArray();
     }
     //date generation
     $date = DateHelper::formatDBDate(date('Y-m-d H:i:s'));
     if (!array_key_exists('id', $data) || array_key_exists('id', $data) && $data['id'] <= 0) {
         $data['created'] = $date;
         $status = 'created';
     } else {
         $row->load($data['id']);
         $oldRow->load($data['id']);
         $status = 'updated';
     }
     $data['modified'] = $date;
     $data['owner_id'] = UsersHelper::getUserId();
     //generate custom field string
     $customArray = array();
     foreach ($data as $name => $value) {
         if (strstr($name, 'custom_') && !strstr($name, '_input') && !strstr($name, "_hidden")) {
             $id = str_replace('custom_', '', $name);
             $customArray[] = array('custom_field_id' => $id, 'custom_field_value' => $value);
             unset($data[$name]);
         }
     }
     // Bind the form fields to the table
     if (!$row->bind($data)) {
         $this->setError($this->db->getErrorMsg());
         return false;
     }
     //$app->triggerEvent('onBeforeCompanySave', array(&$row));
     // 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 = !empty($data['id']) ? $data['id'] : $this->db->insertId();
     ActivityHelper::saveActivity($oldRow, $row, 'company', $status);
     //if we receive no custom post data do not modify the custom fields
     if (count($customArray) > 0) {
         CobaltHelper::storeCustomCf($id, $customArray, 'company');
     }
     //$app->triggerEvent('onAfterCompanySave', array(&$row));
     return $row->id;
 }
Exemple #10
0
 /**
  * Method to store a record
  *
  * @return boolean True on success
  */
 public function store($data = null)
 {
     if ($data) {
         $data = (array) $data;
         $_FILES = array();
         $_FILES['document'] = $data;
         $_FILES['tmp_name'] = $data['attachment'];
         $fileName = $data['value'];
         $fileTemp = $data['attachment'];
         $association_id = $data['association_id'];
         $association_type = $data['association_type'];
         $uploadedFileExtension = substr(strrchr($fileName, '.'), 1);
         $data['is_attachment'] = 1;
         $data['email'] = 1;
     } else {
         $association_id = $_POST['association_id'];
         $association_type = $_POST['association_type'];
         //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 the file extension is ok
         $fileName = $_FILES[$fieldName]['name'];
         $fileTemp = $_FILES[$fieldName]['tmp_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;
     }
     //data generation
     $date = DateHelper::formatDBDate(date('Y-m-d H:i:s'));
     $hashFilename = md5($fileName . $date) . "." . $uploadedFileExtension;
     //lose any special characters in the filename
     $fileName = preg_replace("[^A-Za-z0-9.]", "-", $fileName);
     //always use constants when making file paths, to avoid the possibilty of remote file inclusion
     $uploadPath = JPATH_SITE . '//documents/' . $hashFilename;
     if ($data['is_attachment']) {
         if (!File::write($uploadPath, $fileTemp)) {
             echo TextHelper::_('ERROR MOVING FILE');
             return;
         }
     } else {
         if (!File::upload($fileTemp, $uploadPath)) {
             echo TextHelper::_('ERROR MOVING FILE');
             return;
         }
     }
     $fileSize = filesize($uploadPath);
     //update the database
     $newData = array('name' => $fileName, 'filename' => $hashFilename, 'association_id' => $association_id, 'association_type' => $association_type, 'filetype' => $uploadedFileExtension, 'size' => $fileSize / 1024, 'created' => $date);
     if (array_key_exists('email', $data) && $data['email']) {
         $newData['email'] = 1;
     }
     //Load Tables
     $row = new DocumentTable();
     $oldRow = new DocumentTable();
     //date generation
     $date = DateHelper::formatDBDate(date('Y-m-d H:i:s'));
     if (!array_key_exists('id', $newData)) {
         $newData['created'] = $date;
         $status = "created";
     } else {
         $row->load($data['id']);
         $oldRow->load($data['id']);
         $status = "updated";
     }
     $is_image = is_array(getimagesize($uploadPath)) ? true : false;
     $newData['modified'] = $date;
     $newData['owner_id'] = UsersHelper::getUserId();
     $newData['is_image'] = $is_image;
     // Bind the form fields to the table
     if (!$row->bind($newData)) {
         $this->setError($this->db->getErrorMsg());
         return false;
     }
     $app = \Cobalt\Container::fetch('app');
     //$app->triggerEvent('onBeforeDocumentSave', array(&$row));
     // 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, 'document', $status);
     //$app->triggerEvent('onAfterDocumentSave', array(&$row));
     return $id;
 }