/**
  * Execute search
  *
  * @param void
  * @return null
  */
 function search()
 {
     if (!logged_user()->isProjectUser(active_project())) {
         flash_error(lang('no access permissions'));
         $this->redirectTo('dashboard');
     }
     // if
     $search_for = array_var($_GET, 'search_for');
     $page = (int) array_var($_GET, 'page', 1);
     if ($page < 1) {
         $page = 1;
     }
     if (trim($search_for) == '') {
         $search_results = null;
         $pagination = null;
     } else {
         list($search_results, $pagination) = SearchableObjects::searchPaginated($search_for, active_project(), logged_user()->isMemberOfOwnerCompany(), 10, $page);
     }
     // if
     tpl_assign('search_string', $search_for);
     tpl_assign('current_page', $page);
     tpl_assign('search_results', $search_results);
     tpl_assign('pagination', $pagination);
     $tag_names = plugin_active('tags') ? active_project()->getTagNames() : '';
     tpl_assign('tag_names', $tag_names);
     $this->setSidebar(get_template_path('search_sidebar', 'project'));
 }
 /**
  * Drop all content from table related to $object
  *
  * @param ProjectDataObject $object
  * @return boolean
  */
 static function dropContentByObject(ProjectDataObject $object)
 {
     return SearchableObjects::delete(array('`rel_object_manager` = ? AND `rel_object_id` = ?', get_class($object->manager()), $object->getObjectId()));
 }
Example #3
0
                $projectLinks = array();
                foreach ($dws as $ws) {
                    $projectLinks[] = $ws->getId();
                    echo '<span style="padding-right:5px"><span class="project-replace">' . implode(',', $projectLinks) . '</span></span>';
                }
            }
            if ($search_result["manager"] == 'Projects') {
                ?>
			<span class="project-replace" onclick="Ext.getCmp('tabs-panel').setActiveTab('overview-panel')"><?php 
                echo $object->getId();
                ?>
</span>
		<?php 
            } else {
                $object_name = $object->getObjectName();
                $context_on_name = SearchableObjects::getContext($object_name, $search_string);
                if ($context_on_name != '') {
                    $object_name = $context_on_name;
                } else {
                    $object_name = clean($object_name);
                }
                if ($object instanceof MailContent && $object->getHasAttachments()) {
                    $linkIcon = 'link-ico ico-attachment';
                } else {
                    $linkIcon = '';
                }
                ?>
			<a class="<?php 
                echo $linkIcon;
                ?>
" href="<?php 
 function clearObjectProperties()
 {
     ObjectProperties::deleteAllByObject($this);
     if ($this->isSearchable()) {
         SearchableObjects::dropObjectPropertiesByObject($this);
     }
 }
 /**
  * Adds the custom properties of an object into the database.
  * 
  * @param $object
  * @return unknown_type
  */
 function add_custom_properties($object)
 {
     if (logged_user()->isGuest()) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     $obj_custom_properties = array_var($_POST, 'object_custom_properties');
     $customProps = CustomProperties::getAllCustomPropertiesByObjectType($object->getObjectTypeId());
     //Sets all boolean custom properties to 0. If any boolean properties are returned, they are subsequently set to 1.
     foreach ($customProps as $cp) {
         if ($cp->getType() == 'boolean') {
             $custom_property_value = CustomPropertyValues::getCustomPropertyValue($object->getId(), $cp->getId());
             if (!$custom_property_value instanceof CustomPropertyValue) {
                 $custom_property_value = new CustomPropertyValue();
             }
             $custom_property_value->setObjectId($object->getId());
             $custom_property_value->setCustomPropertyId($cp->getId());
             $custom_property_value->setValue(0);
             $custom_property_value->save();
         }
     }
     if (is_array($obj_custom_properties)) {
         foreach ($obj_custom_properties as $id => $value) {
             //Get the custom property
             $custom_property = null;
             foreach ($customProps as $cp) {
                 if ($cp->getId() == $id) {
                     $custom_property = $cp;
                     break;
                 }
             }
             if ($custom_property instanceof CustomProperty) {
                 // save dates in standard format "Y-m-d H:i:s", because the column type is string
                 if ($custom_property->getType() == 'date') {
                     if (is_array($value)) {
                         $newValues = array();
                         foreach ($value as $val) {
                             $dtv = DateTimeValueLib::dateFromFormatAndString(user_config_option('date_format'), $val);
                             $newValues[] = $dtv->format("Y-m-d H:i:s");
                         }
                         $value = $newValues;
                     } else {
                         $dtv = DateTimeValueLib::dateFromFormatAndString(user_config_option('date_format'), $value);
                         $value = $dtv->format("Y-m-d H:i:s");
                     }
                 }
                 //Save multiple values
                 if (is_array($value)) {
                     CustomPropertyValues::deleteCustomPropertyValues($object->getId(), $id);
                     foreach ($value as &$val) {
                         if (is_array($val)) {
                             // CP type == table
                             $str_val = '';
                             foreach ($val as $col_val) {
                                 $col_val = str_replace("|", "\\|", $col_val);
                                 $str_val .= ($str_val == '' ? '' : '|') . $col_val;
                             }
                             $val = $str_val;
                         }
                         if ($val != '') {
                             if (strpos($val, ',')) {
                                 $val = str_replace(',', '|', $val);
                             }
                             $custom_property_value = new CustomPropertyValue();
                             $custom_property_value->setObjectId($object->getId());
                             $custom_property_value->setCustomPropertyId($id);
                             $custom_property_value->setValue($val);
                             $custom_property_value->save();
                         }
                     }
                 } else {
                     if ($custom_property->getType() == 'boolean') {
                         $value = isset($value);
                     }
                     $cpv = CustomPropertyValues::getCustomPropertyValue($object->getId(), $id);
                     if ($cpv instanceof CustomPropertyValue) {
                         $custom_property_value = $cpv;
                     } else {
                         $custom_property_value = new CustomPropertyValue();
                     }
                     $custom_property_value->setObjectId($object->getId());
                     $custom_property_value->setCustomPropertyId($id);
                     $custom_property_value->setValue($value);
                     $custom_property_value->save();
                 }
                 //Add to searchable objects
                 if ($object->isSearchable() && ($custom_property->getType() == 'text' || $custom_property->getType() == 'list' || $custom_property->getType() == 'numeric')) {
                     $name = $custom_property->getName();
                     $searchable_object = SearchableObjects::findOne(array("conditions" => "`rel_object_id` = " . $object->getId() . " AND `column_name` = '{$name}'"));
                     if (!$searchable_object) {
                         $searchable_object = new SearchableObject();
                     }
                     if (is_array($value)) {
                         $value = implode(', ', $value);
                     }
                     $searchable_object->setRelObjectId($object->getId());
                     $searchable_object->setColumnName($name);
                     $searchable_object->setContent($value);
                     $searchable_object->save();
                 }
             }
         }
     }
 }
 /**
  * Drop columns content from table related to $object
  *
  * @param ApplicationDataObject $object
  * @return boolean
  */
 static function dropContentByObjectColumns(ApplicationDataObject $object, $columns = array())
 {
     $columns_csv = "'" . implode("','", $columns) . "'";
     return SearchableObjects::delete(array('`rel_object_id` = ? AND `column_name` in (' . $columns_csv . ')', $object->getObjectId()));
 }
 /**
  * Return manager instance
  *
  * @access protected
  * @param void
  * @return SearchableObjects 
  */
 function manager()
 {
     if (!$this->manager instanceof SearchableObjects) {
         $this->manager = SearchableObjects::instance();
     }
     return $this->manager;
 }
Example #8
0
	function delete($deleteMails = false){
		MailAccountContacts::deleteByAccount($this);
		if ($deleteMails) {
			session_commit();
			ini_set('memory_limit', '1024M');
			
			LinkedObjects::delete(array("(`object_id` IN (SELECT `object_id` FROM `".TABLE_PREFIX."mail_contents` WHERE `account_id` = " . DB::escape($this->getId()).")) 
				or (`rel_object_id` IN (SELECT `object_id` FROM `".TABLE_PREFIX."mail_contents` WHERE `account_id` = " . DB::escape($this->getId())."))")); 
			
      		SearchableObjects::delete(array("`rel_object_id` IN (SELECT `object_id` FROM `".TABLE_PREFIX."mail_contents` WHERE `account_id` = " . DB::escape($this->getId()).") "));
			ReadObjects::delete("`rel_object_id` IN (SELECT `object_id` FROM `".TABLE_PREFIX."mail_contents` WHERE `account_id` = " . DB::escape($this->getId()).") ");
			
			$account_email_ids = MailContents::findAll(array('id' => true, 'conditions' => '`account_id` = ' . DB::escape($this->getId()), 'include_trashed' => true));
			if (count($account_email_ids) > 0) {
				MailDatas::delete('id IN ('.implode(',', $account_email_ids).')');
				MailContents::delete('`account_id` = ' . DB::escape($this->getId()));
			}
		}
		if ($this->getIsImap()) {
			MailAccountImapFolders::delete('account_id = ' . $this->getId());
		}
		parent::delete();
	}
 /**
  * Save object. If object is searchable this function will add conetent of searchable fields 
  * to search index
  *
  * @param void
  * @return boolean
  */
 function save()
 {
     $result = parent::save();
     // If searchable refresh content in search table
     if ($this->isSearchable()) {
         SearchableObjects::dropContentByObject($this);
         $project = $this->getProject();
         foreach ($this->getSearchableColumns() as $column_name) {
             $content = $this->getSearchableColumnContent($column_name);
             if (trim($content) != '') {
                 $searchable_object = new SearchableObject();
                 $searchable_object->setRelObjectManager(get_class($this->manager()));
                 $searchable_object->setRelObjectId($this->getObjectId());
                 $searchable_object->setColumnName($column_name);
                 $searchable_object->setContent($content);
                 if ($project instanceof Project) {
                     $searchable_object->setProjectId($project->getId());
                 }
                 $searchable_object->setIsPrivate($this->isPrivate());
                 $searchable_object->save();
             }
             // if
         }
         // if
     }
     // if
     return $result;
 }
 /**
  * This event is triggered when comment that belongs to this object is deleted
  *
  * @param Comment $comment
  * @return boolean
  */
 function onDeleteComment(Comment $comment)
 {
     if ($this->isSearchable()) {
         SearchableObjects::dropContentByObjectColumn($this, 'comment' . $comment->getId());
     }
 }
 function delete($deleteMails = false)
 {
     MailAccountUsers::deleteByAccount($this);
     if ($deleteMails) {
         session_commit();
         LinkedObjects::delete(array("(`object_id` IN (SELECT `id` FROM `" . TABLE_PREFIX . "mail_contents` WHERE `account_id` = " . DB::escape($this->getId()) . ") and `object_manager` = 'MailContents') \n\t\t\t\tor (`rel_object_id` IN (SELECT `id` FROM `" . TABLE_PREFIX . "mail_contents` WHERE `account_id` = " . DB::escape($this->getId()) . ") and `rel_object_manager` = 'MailContents')"));
         SearchableObjects::delete(array("`rel_object_manager` = 'MailContents' AND `rel_object_id` IN (SELECT `id` FROM `" . TABLE_PREFIX . "mail_contents` WHERE `account_id` = " . DB::escape($this->getId()) . ") "));
         ReadObjects::delete("`rel_object_manager` = 'MailContents' AND `rel_object_id` IN (SELECT `id` FROM `" . TABLE_PREFIX . "mail_contents` WHERE `account_id` = " . DB::escape($this->getId()) . ") ");
         $account_emails = MailContents::findAll(array('conditions' => '`account_id` = ' . DB::escape($this->getId()), 'include_trashed' => true));
         foreach ($account_emails as $email) {
             $email->delete();
         }
         //MailContents::delete('`account_id` = ' . DB::escape($this->getId()));
     }
     if ($this->getIsImap()) {
         MailAccountImapFolders::delete('account_id = ' . $this->getId());
     }
     parent::delete();
 }
 function addTagsToSearchableObject()
 {
     $tag_names = $this->getTagNames();
     if (is_array($tag_names) && count($tag_names) > 0) {
         if (!$this->isNew()) {
             SearchableObjects::dropContentByObjectColumn($this, 'tags');
         }
         $searchable_object = new SearchableObject();
         $searchable_object->setRelObjectManager(get_class($this->manager()));
         $searchable_object->setRelObjectId($this->getObjectId());
         $searchable_object->setColumnName('tags');
         $searchable_object->setContent(implode(' ', $tag_names));
         $searchable_object->setIsPrivate($this->isPrivate());
         $searchable_object->save();
     }
 }
 function addToSearchableObjects($wasNew = false)
 {
     $columns_to_drop = array();
     if ($wasNew) {
         $columns_to_drop = $this->getSearchableColumns();
     } else {
         foreach ($this->getSearchableColumns() as $column_name) {
             if (isset($this->searchable_composite_columns[$column_name])) {
                 foreach ($this->searchable_composite_columns[$column_name] as $colName) {
                     if ($this->isColumnModified($colName)) {
                         $columns_to_drop[] = $column_name;
                         break;
                     }
                 }
             } else {
                 if ($column_name == 'body') {
                     $columns_to_drop[] = $column_name;
                 } else {
                     if ($this->getMailData()->columnExists($column_name) && $this->getMailData()->isColumnModified($column_name)) {
                         $columns_to_drop[] = $column_name;
                     } else {
                         if ($this->isColumnModified($column_name)) {
                             $columns_to_drop[] = $column_name;
                         }
                     }
                 }
             }
         }
     }
     if (count($columns_to_drop) > 0) {
         SearchableObjects::dropContentByObjectColumns($this, $columns_to_drop);
         foreach ($columns_to_drop as $column_name) {
             $content = $this->getSearchableColumnContent($column_name);
             if (trim($content) != '') {
                 $searchable_object = SearchableObjects::findById(array('rel_object_id' => $this->getObjectId(), 'column_name' => $column_name));
                 if (!$searchable_object instanceof SearchableObject) {
                     $searchable_object = new SearchableObject();
                     $searchable_object->setRelObjectId($this->getObjectId());
                     $searchable_object->setColumnName($column_name);
                 }
                 $searchable_object->setContent($content);
                 $searchable_object->setContactId($this->getAccount() instanceof MailAccount ? $this->getAccount()->getContactId() : 0);
                 $searchable_object->save();
             }
             // if
         }
         // foreach
     }
     // if
     $rows = DB::executeAll("select column_name from " . TABLE_PREFIX . "searchable_objects where rel_object_id=" . $this->getObjectId());
     if ($wasNew) {
         SearchableObjects::dropContentByObjectColumn($this, 'uid');
         $searchable_object = new SearchableObject();
         $searchable_object->setRelObjectId($this->getObjectId());
         $searchable_object->setColumnName('uid');
         $searchable_object->setContent($this->getUniqueObjectId());
         $searchable_object->setContactId($this->getAccount() instanceof MailAccount ? $this->getAccount()->getContactId() : 0);
         $searchable_object->save();
     }
     $rows = DB::executeAll("select column_name from " . TABLE_PREFIX . "searchable_objects where rel_object_id=" . $this->getObjectId());
 }
 function search()
 {
     ajx_current('empty');
     if (!can_manage_contacts(logged_user())) {
         flash_error(lang("no access permissions"));
         return;
     }
     $search_for = array_var($_POST, 'search_for', false);
     if ($search_for) {
         $search_results = SearchableObjects::searchByType($search_for, null, 'Companies', true, 50);
         $companies = $search_results[0];
         if ($companies && count($companies) > 0) {
             $result = array();
             foreach ($companies as $companyResult) {
                 $company = $companyResult['object'];
                 $result[] = array('name' => $company->getName(), 'id' => $company->getId(), 'phone' => $company->getPhoneNumber(), 'email' => $company->getEmail());
             }
             ajx_extra_data(array("results" => $result));
         }
     }
 }
 /**
  * Execute search
  *
  * @param void
  * @return null
  */
 function search()
 {
     ajx_set_panel("search");
     $timeBegin = microtime(true);
     if (active_project() && !logged_user()->isProjectUser(active_project())) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     // if
     $search_for = array_var($_GET, 'search_for');
     $page = (int) array_var($_GET, 'page', 1);
     if ($page < 1) {
         $page = 1;
     }
     if (trim($search_for) == '') {
         $search_results = null;
         $pagination = null;
     } else {
         if (active_project()) {
             $projects = active_project()->getId();
         } else {
             $projects = null;
         }
         list($search_results, $pagination) = SearchableObjects::searchPaginated($search_for, $projects, logged_user()->isMemberOfOwnerCompany());
     }
     // if
     $timeEnd = microtime(true);
     tpl_assign('search_string', $search_for);
     tpl_assign('current_page', $page);
     tpl_assign('search_results', $search_results);
     tpl_assign('pagination', $pagination);
     tpl_assign('time', $timeEnd - $timeBegin);
 }
 /**
  * Execute search
  *
  * @param void
  * @return null
  */
 function searchbytype()
 {
     $this->setTemplate('search');
     if (active_project() && !logged_user()->isProjectUser(active_project())) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     // if
     $page = array_var($_GET, 'page');
     $pageType = array_var($_GET, 'page_type');
     $search_for = array_var($_GET, 'search_for');
     $manager = array_var($_GET, 'manager');
     $objectManagers = array("ProjectWebpages", "ProjectMessages", "MailContents", "ProjectFiles", "ProjectFileRevisions", "ProjectMilestones", "ProjectTasks", "ProjectEvents");
     $objectTypes = array(lang('webpages'), lang('messages'), lang('emails'), lang('files'), lang('files'), lang('milestones'), lang('tasks'), lang('events'));
     $iconTypes = array('webpage', 'message', 'email', 'file', 'file', 'milestone', 'task', 'event');
     $search_results = array();
     $timeBegin = microtime(true);
     if (trim($search_for) == '') {
         $search_results = null;
         $pagination = null;
     } else {
         if (array_var($_GET, 'search_all_projects') != "true" && active_project() instanceof Project) {
             $projects = active_project()->getAllSubWorkspacesCSV(true);
         } else {
             $projects = null;
         }
         switch ($manager) {
             case 'Contacts':
             case 'Companies':
                 $search_results = $this->searchContacts($search_for, array(), 20, $page);
                 break;
             case 'Projects':
                 $search_results = $this->searchWorkspaces($search_for, array(), 20, $page);
                 break;
             case 'Users':
                 $search_results = $this->searchUsers($search_for, array(), 20, $page);
                 break;
             default:
                 $user_id = $manager == "MailContents" ? logged_user()->getId() : 0;
                 $results = SearchableObjects::searchByType($search_for, $projects, $manager, true, 20, $page, null, $user_id);
                 if (count($results[0]) > 0) {
                     $c = array_search($manager, $objectManagers);
                     $sr = array();
                     $pagination = $results[1];
                     $sr['result'] = $results[0];
                     $sr['pagination'] = $pagination;
                     $sr['type'] = $objectTypes[$c];
                     $sr['icontype'] = $iconTypes[$c];
                     $sr['manager'] = $manager;
                     $search_results[] = $sr;
                 }
                 break;
         }
     }
     // if
     $timeEnd = microtime(true);
     tpl_assign('search_string', $search_for);
     tpl_assign('search_results', $search_results);
     tpl_assign('time', $timeEnd - $timeBegin);
     tpl_assign('enable_pagination', true);
 }
 /**
 * Return manager instance
 *
 * @access protected
 * @param void
 * @return SearchableObjects 
 */
 function manager() {
   if(!($this->manager instanceof SearchableObjects)) $this->manager = SearchableObjects::instance();
   return $this->manager;
 } // manager
 /**
  * This function will return paginated result. Result is an array where first element is 
  * array of returned object and second populated pagination object that can be used for 
  * obtaining and rendering pagination data using various helpers.
  * 
  * Items and pagination array vars are indexed with 0 for items and 1 for pagination
  * because you can't use associative indexing with list() construct
  *
  * @access public
  * @param array $arguments Query argumens (@see find()) Limit and offset are ignored!
  * @param integer $items_per_page Number of items per page
  * @param integer $current_page Current page number
  * @return array
  */
 function paginate($arguments = null, $items_per_page = 10, $current_page = 1)
 {
     if (isset($this) && instance_of($this, 'SearchableObjects')) {
         return parent::paginate($arguments, $items_per_page, $current_page);
     } else {
         return SearchableObjects::instance()->paginate($arguments, $items_per_page, $current_page);
         //$instance =& SearchableObjects::instance();
         //return $instance->paginate($arguments, $items_per_page, $current_page);
     }
     // if
 }
Example #19
0
    function addToSearchableObjects($wasNew = false){
    	$columns_to_drop = array();
    	if ($wasNew)
    		$columns_to_drop = $this->getSearchableColumns();
    	else {
			foreach ($this->getSearchableColumns() as $column_name){
				if (isset($this->searchable_composite_columns[$column_name])){
					foreach ($this->searchable_composite_columns[$column_name] as $colName){
						if ($this->isColumnModified($colName)){
							$columns_to_drop[] = $column_name;
							break;
						}
					}
				} else if ($column_name == 'body') {
					$columns_to_drop[] = $column_name;
				} else if ($this->getMailData()->columnExists($column_name) && $this->getMailData()->isColumnModified($column_name)) {
					$columns_to_drop[] = $column_name;
				} else if ($this->isColumnModified($column_name)) {
					$columns_to_drop[] = $column_name;
				}
			}
    	}
    	
    	if (count($columns_to_drop) > 0){
    		SearchableObjects::dropContentByObjectColumns($this,$columns_to_drop);
    		
	        foreach($columns_to_drop as $column_name) {
	          $content = $this->getSearchableColumnContent($column_name);
	          if(trim($content) <> '') {

	            $searchable_object = new SearchableObject();
	            
	            $searchable_object->setRelObjectId($this->getObjectId());
	            $searchable_object->setColumnName($column_name);
	            $searchable_object->setContent($content);
	            $searchable_object->setContactId($this->getAccount() instanceof MailAccount ? $this->getAccount()->getContactId() : 0);
	            //$searchable_object->setProjectId(0); TODO Feng 2 setDefault Member
	            $searchable_object->save();
	          } // if
	        } // foreach
    	} // if
    	
    	if ($wasNew){
        	SearchableObjects::dropContentByObjectColumns($this,array('uid'));
        	$searchable_object = new SearchableObject();
            
            $searchable_object->setRelObjectId($this->getObjectId());
            $searchable_object->setColumnName('uid');
            $searchable_object->setContent($this->getUniqueObjectId());

            
            $searchable_object->save();
        }
    }
 function search()
 {
     ajx_current('empty');
     if (!can_manage_contacts(logged_user())) {
         flash_error(lang("no access permissions"));
         return;
     }
     $search_for = array_var($_POST, 'search_for', false);
     if ($search_for) {
         /*if (active_project() instanceof Project) {
         			$projects = active_project()->getAllSubWorkspacesQuery(false);
         		} else {*/
         $projects = null;
         //}
         $search_results = SearchableObjects::searchByType($search_for, $projects, 'Contacts', true, 50);
         $contacts = $search_results[0];
         if ($contacts && count($contacts) > 0) {
             $result = array();
             foreach ($contacts as $contactResult) {
                 $contact = $contactResult['object'];
                 $result[] = array('name' => $contact->getFirstname() . ' ' . $contact->getLastname(), 'phone' => $contact->getWPhoneNumber(), 'email' => $contact->getEmail(), 'jobtitle' => $contact->getJobTitle(), 'company' => $contact->getCompany() instanceof Company ? array('id' => $contact->getCompany()->getId(), 'name' => $contact->getCompany()->getName(), 'phone' => $contact->getCompany()->getPhoneNumber(), 'email' => $contact->getCompany()->getEmail()) : array(), 'department' => $contact->getDepartment(), 'id' => $contact->getId());
             }
             ajx_extra_data(array("results" => $result));
         }
     }
 }