public function execute()
 {
     $model = new DocumentModel();
     $document = $model->getDocument();
     $filename = basename($document->name);
     $file_extension = strtolower(substr(strrchr($filename, "."), 1));
     switch ($file_extension) {
         case "gif":
             $ctype = "image/gif";
             break;
         case "png":
             $ctype = "image/png";
             break;
         case "jpeg":
         case "jpg":
             $ctype = "image/jpg";
             break;
         default:
     }
     header('Content-type: ' . $ctype);
     ob_clean();
     flush();
     readfile($document->path);
     exit;
 }
 public function execute()
 {
     $model = new DocumentModel();
     $document = $model->getDocument();
     $filename = basename($document->name);
     header('Content-Description: File Transfer');
     header('Content-Type: application/octet-stream');
     header('Content-Disposition: attachment; filename=' . $filename);
     header('Expires: 0');
     header('Cache-Control: must-revalidate');
     header('Pragma: public');
     header('Content-Length: ' . filesize($document->path));
     readfile($document->path);
     exit;
 }
Beispiel #3
0
 public function render($tpl = null)
 {
     $app = JFactory::getApplication();
     //get model
     $model = new DocumentModel();
     $documents = $model->getDocuments($app->input->get('document_id'));
     $state = $model->getState();
     $layout = $this->getLayout();
     if ($app->input->get('document_id') && $layout != "document_row") {
         $documents = $documents[0];
     }
     //assign refs
     $this->documents = $documents;
     $this->state = $state;
     //display view
     echo parent::render();
 }
Beispiel #4
0
 public function getDealDetails(&$deal)
 {
     $closed_stages = DealHelper::getClosedStages();
     $deal->closed = in_array($deal->stage_id, $closed_stages) ? TRUE : FALSE;
     $deal_id = $deal->id;
     /** ------------------------------------------
      *  Join contacts
      */
     $peopleModel = new People();
     $peopleModel->set('deal_id', $deal_id);
     $people = $peopleModel->getContacts();
     //assign results to company
     $deal->people = $people;
     /** ------------------------------------------
      *  Join conversations
      */
     $convoModel = new Conversation();
     $convoModel->set('deal_id', $deal_id);
     $conversations = $convoModel->getConversations();
     $deal->conversations = $conversations;
     /** ------------------------------------------
      *  Join notes
      */
     $notesModel = new Note();
     $deal->notes = $notesModel->getNotes($deal_id, 'deal');
     /** ------------------------------------------
      *  Join documents
      */
     $docModel = new Document();
     $docModel->set('deal_id', $deal_id);
     $deal->documents = $docModel->getDocuments();
     /** ------------------------------------------
      *  Join tasks & events
      */
     $eventModel = new Event();
     $eventModel->set('deal_id', $deal_id);
     $events = $eventModel->getEvents();
     $deal->events = $events;
 }
Beispiel #5
0
 /**
  * Store email attachments to local device
  * @param [mixed]  $attachments [array of attachments]
  * @param [String] $location    [storage location]
  */
 private function _storeAttachments($attachments, $key, $location = "person")
 {
     if (is_array($attachments) && count($attachments) > 0) {
         $model = new Document();
         foreach ($attachments as $attachment_key => $attachment) {
             $attachment->association_id = $key;
             $attachment->association_type = $location;
             $attachment->email = 1;
             $model->store($attachment);
         }
     }
 }
Beispiel #6
0
 public static function downloadDocument()
 {
     $model = new DocumentModel();
     $document = $model->getDocument();
     header('Content-Description: File Transfer');
     header('Content-Type: application/octet-stream');
     header('Content-Disposition: attachment; filename=' . basename($document->name));
     header('Content-Transfer-Encoding: binary');
     header('Expires: 0');
     header('Cache-Control: must-revalidate');
     header('Pragma: public');
     header('Content-Length: ' . filesize($document->path));
     ob_clean();
     flush();
     readfile($document->path);
     exit;
 }
Beispiel #7
0
 public function getPerson($id = null)
 {
     $app = \Cobalt\Container::fetch('app');
     $id = $id ? $id : $app->input->get('id');
     if ($id > 0) {
         $db = JFactory::getDBO();
         //generate query
         //
         $query = $db->getQuery(true);
         $query->select('p.*,c.name as company_name,stat.name as status_name,
                         source.name as source_name, owner.name as owner_name, crmery_user.first_name AS owner_first_name, crmery_user.last_name AS owner_last_name');
         $query->from('#__people AS p');
         $query->leftJoin('#__companies AS c ON c.id = p.company_id AND c.published>0');
         $query->leftJoin('#__people_status AS stat ON stat.id = p.status_id');
         $query->leftJoin('#__sources AS source ON source.id = p.source_id');
         $query->leftJoin('#__users AS owner ON p.owner_id = owner.id');
         $query->leftJoin("#__users AS crmery_user ON crmery_user.id = p.owner_id");
         //searching for specific person
         $query->where("p.published=" . $this->published);
         $query->where("p.id='" . $id . "'");
         //run query and grab results
         $db->setQuery($query);
         $person = $db->loadAssoc();
         /* Deals */
         $dealModel = new Deal();
         $dealModel->set('person_id', $person['id']);
         $person['deals'] = $dealModel->getDeals();
         /* Notes */
         $notesModel = new Note();
         $person['notes'] = $notesModel->getNotes($person['id'], 'person');
         /* Docs */
         $docsModel = new Document();
         $docsModel->set('person_id', $person['id']);
         $person['documents'] = $docsModel->getDocuments();
         /* Tweets */
         if ($person['twitter_user'] != "" && $person['twitter_user'] != " ") {
             $person['tweets'] = TweetsHelper::getTweets($person['twitter_user']);
         }
         $this->person = $person;
     } else {
         //TODO update things to OBJECTS
         $person = (array) new PeopleTable();
         $this->person = $person;
     }
     //$app->triggerEvent('onPersonLoad', array(&$person));
     return $person;
 }
Beispiel #8
0
 public function render()
 {
     $layout = $this->getLayout();
     //get model
     $model = new DocumentModel();
     $documents = $model->getDocuments();
     $state = $model->getState();
     //add js
     $document = JFactory::getDocument();
     $document->addScript(JURI::base() . 'src/Cobalt/media/js/document_manager.js');
     //session data
     $session = JFactory::getSession();
     $member_role = UsersHelper::getRole();
     $user_id = UsersHelper::getUserId();
     //associations
     $assoc = $session->get('document_assoc_filter');
     $assoc_names = DocumentHelper::getAssocTypes();
     $assoc_name = $assoc ? $assoc_names[$assoc] : $assoc_names['all'];
     //users
     $user_id = UsersHelper::getUserId();
     $user = $session->get('document_user_filter');
     $team = $session->get('document_team_filter');
     if ($user == "all") {
         $user_name = TextHelper::_('COBALT_ALL_USERS');
     } elseif ($user && $user != $user_id) {
         $user_info = UsersHelper::getUser($user);
         $user_name = $user_info->first_name . " " . $user_info->last_name;
     } elseif ($team) {
         $team_info = UsersHelper::getTeams($team);
         $team_info = $team_info[0];
         $user_name = $team_info['team_name'] . TextHelper::_('COBALT_TEAM_APPEND');
     } else {
         $user_name = TextHelper::_('COBALT_ME');
     }
     if ($layout == 'default') {
         $total = $model->getTotal();
         $pagination = $model->getPagination();
         $this->dataTableColumns = $model->getDataTableColumns();
         JFactory::getDocument()->addScriptDeclaration("\n            var loc = 'documents';\n            var order_dir = '" . $state->get('People.filter_order_Dir') . "';\n            var order_col = '" . $state->get('People.filter_order') . "';\n            var dataTableColumns = " . json_encode($this->dataTableColumns) . ";");
     }
     //type
     $type = $session->get('document_type_filter');
     $type_names = DocumentHelper::getDocTypes();
     $type_name = $type && array_key_exists($type, $type_names) ? $type_names[$type] : $type_names['all'];
     //teams
     $teams = UsersHelper::getTeams();
     //users
     $users = UsersHelper::getUsers();
     //list view
     $document_list = ViewHelper::getView('documents', 'list', 'phtml', array('documents' => $documents, 'state' => $state, 'total' => $total, 'pagination' => $pagination));
     if ($layout == "download") {
         DealHelper::downloadDocument();
     }
     //assign ref
     $this->state = $state;
     $this->document_list = $document_list;
     $this->assoc_names = $assoc_names;
     $this->assoc_name = $assoc_name;
     $this->user_name = $user_name;
     $this->type_names = $type_names;
     $this->type_name = $type_name;
     $this->member_role = $member_role;
     $this->user_id = $user_id;
     $this->teams = $teams;
     $this->users = $users;
     //display
     return parent::render();
 }
Beispiel #9
0
 public function getCompanies($id = null, $type = null, $user = null, $team = null)
 {
     $app = \Cobalt\Container::fetch('app');
     $this->_id = $id;
     $this->_type = $type;
     $this->_user = $user;
     $this->_team = $team;
     //get query string
     $query = $this->_buildQuery();
     /** ------------------------------------------
      * Set query limits and load results
      */
     if (!TemplateHelper::isMobile()) {
         $limit = $this->getState($this->_view . '_limit');
         $limitStart = $this->getState($this->_view . '_limitstart');
         if (!$this->_id && $limit != 0) {
             if ($limitStart >= $this->getTotal()) {
                 $limitStart = 0;
                 $limit = 10;
                 $limitStart = $limit != 0 ? floor($limitStart / $limit) * $limit : 0;
                 $this->state->set($this->_view . '_limit', $limit);
                 $this->state->set($this->_view . '_limitstart', $limitStart);
             }
             $query .= " LIMIT " . $limit . " OFFSET " . $limitStart;
         }
     }
     //run query and grab results of companies
     $companies = $this->db->setQuery($query)->loadAssocList();
     //generate query to join people
     if (count($companies)) {
         $export = $app->input->get('export');
         if (!$export) {
             foreach ($companies as $key => $company) {
                 /* Tweets */
                 if ($company['twitter_user'] != "" && $company['twitter_user'] != " ") {
                     $companies[$key]['tweets'] = TweetsHelper::getTweets($company['twitter_user']);
                 }
                 //generate people query
                 $peopleModel = new People();
                 $peopleModel->set('company_id', $company['id']);
                 $companies[$key]['people'] = $peopleModel->getContacts();
                 //generate deal query
                 $dealModel = new Deal();
                 $dealModel->set('company_id', $company['id']);
                 $deals = $dealModel->getDeals();
                 $companies[$key]['pipeline'] = 0;
                 $companies[$key]['won_deals'] = 0;
                 for ($i = 0; $i < count($deals); $i++) {
                     $deal = $deals[$i];
                     $companies[$key]['pipeline'] += $deal->amount;
                     if ($deal->percent == 100) {
                         $companies[$key]['won_deals'] += $deal->amount;
                     }
                 }
                 $companies[$key]['deals'] = $deals;
                 //Get Associated Notes
                 $notesModel = new Note();
                 $companies[$key]['notes'] = $notesModel->getNotes($company['id'], 'company');
                 // Get Associated Documents
                 $documentModel = new Document();
                 $documentModel->set('company_id', $company['id']);
                 $companies[$key]['documents'] = $documentModel->getDocuments();
                 $companies[$key]['address_formatted'] = strlen($company['address_1']) > 0 ? $company['address_1'] . $company['address_2'] . ", " . $company['address_city'] . ' ' . $company['address_state'] . ', ' . $company['address_zip'] . ' ' . $company['address_country'] : "";
             }
         }
     }
     //$app->triggerEvent('onCompanyLoad',array(&$companies));
     return $companies;
 }