/**
  * Returns a list of emails according to the requested parameters
  *
  * @param string $tag
  * @param array $attributes
  * @param Project $project
  * @return array
  */
 function getEmails($account_id = null, $state = null, $read_filter = "", $classif_filter = "", $context = null, $start = null, $limit = null, $order_by = 'received_date', $dir = 'ASC', $join_params = null, $archived = false, $conversation_list = null, $only_count_result = false)
 {
     $mailTablePrefix = "e";
     if (!$limit) {
         $limit = user_config_option('mails_per_page') ? user_config_option('mails_per_page') : config_option('files_per_page');
     }
     $accountConditions = "";
     // Check for accounts
     $accountConditions = '';
     if (isset($account_id) && $account_id > 0) {
         //Single account
         $accountConditions = " AND {$mailTablePrefix}.account_id = " . DB::escape($account_id);
     } else {
         // show mails for all visible accounts and classified mails where logged_user has permissions so we don't filter by account_id
         /*// show emails from other accounts
         		$macs = MailAccountContacts::instance()->getByContact(logged_user());
         		$acc_ids = array(0);
         		foreach ($macs as $mac) $acc_ids[] = $mac->getAccountId();
         		
         		// permission conditions
         		$pgs = ContactPermissionGroups::getPermissionGroupIdsByContactCSV(logged_user()->getId());
         		if (trim($pgs == '')) $pgs = '0';
         		$perm_sql = "(SELECT count(*) FROM ".TABLE_PREFIX."sharing_table st WHERE st.object_id = $mailTablePrefix.object_id AND st.group_id IN ($pgs)) > 0";
         		
         		// show mails for all visible accounts and classified mails where logged_user has permissions
         		$accountConditions = " AND ($mailTablePrefix.account_id IN (" . implode(",", $acc_ids) . ") OR $perm_sql)";*/
     }
     // Check for unclassified emails
     $classified = '';
     if ($classif_filter != '' && $classif_filter != 'all') {
         $persons_dim = Dimensions::findByCode('feng_persons');
         $persons_dim_id = $persons_dim instanceof Dimension ? $persons_dim->getId() : "0";
         $classified = "AND " . ($classif_filter == 'unclassified' ? "NOT " : "");
         $classified .= "o.id IN (SELECT om.object_id FROM " . TABLE_PREFIX . "object_members om INNER JOIN " . TABLE_PREFIX . "members m ON m.id=om.member_id WHERE m.dimension_id<>{$persons_dim_id})";
     }
     // if not filtering by account or classification then check that emails are classified or from one of my accounts
     if ($classified == '' && $accountConditions == '') {
         $macs = MailAccountContacts::instance()->getByContact(logged_user());
         $acc_ids = array(0);
         foreach ($macs as $mac) {
             $acc_ids[] = $mac->getAccountId();
         }
         $accountConditions = " AND ({$mailTablePrefix}.account_id IN (" . implode(',', $acc_ids) . ") OR EXISTS (\r\n\t\t\t\t\tSELECT om1.object_id FROM " . TABLE_PREFIX . "object_members om1 \r\n\t\t\t\t\t\tINNER JOIN " . TABLE_PREFIX . "members m1 ON m1.id=om1.member_id \r\n\t\t\t\t\t\tINNER JOIN " . TABLE_PREFIX . "dimensions d1 ON d1.id=m1.dimension_id \r\n\t\t\t\t\tWHERE om1.object_id={$mailTablePrefix}.object_id AND d1.is_manageable=1) ) ";
     }
     // Check for draft, junk, etc. emails
     if ($state == "draft") {
         $stateConditions = " {$mailTablePrefix}.state = '2'";
     } else {
         if ($state == "sent") {
             $stateConditions = " {$mailTablePrefix}.state IN ('1','3','5')";
         } else {
             if ($state == "received") {
                 $stateConditions = " {$mailTablePrefix}.state IN ('0','5')";
             } else {
                 if ($state == "junk") {
                     $stateConditions = " {$mailTablePrefix}.state = '4'";
                 } else {
                     if ($state == "outbox") {
                         $stateConditions = " {$mailTablePrefix}.state >= 200";
                     } else {
                         $stateConditions = "";
                     }
                 }
             }
         }
     }
     // Check read emails
     if ($read_filter != "" && $read_filter != "all") {
         if ($read_filter == "unread") {
             $read = "AND NOT ";
             $subread = "AND NOT mc.";
         } else {
             $read = "AND ";
             $subread = "AND mc.";
         }
         $read2 = "id IN (SELECT rel_object_id FROM " . TABLE_PREFIX . "read_objects t WHERE contact_id = " . logged_user()->getId() . " AND id = t.rel_object_id AND t.is_read = '1')";
         $read .= $read2;
         $subread .= $read2;
     } else {
         $read = "";
         $subread = "";
     }
     $conversation_cond = "";
     $box_cond = "AND {$stateConditions}";
     if (isset($conversation_list) && $conversation_list > 0) {
         $conversation_cond = "AND e.conversation_last = 1";
     }
     $extra_conditions = "{$accountConditions} {$classified} {$read} {$conversation_cond} {$box_cond}";
     Hook::fire("listing_extra_conditions", null, $extra_conditions);
     return self::instance()->listing(array('limit' => $limit, 'start' => $start, 'order' => $order_by, 'order_dir' => $dir, 'extra_conditions' => $extra_conditions, 'count_results' => false, 'only_count_results' => $only_count_result, 'join_params' => $join_params));
 }
Ejemplo n.º 2
0
	/**
	 * Override defaults. 
	 * Also adds mail to sharing table if is not categorized. 
	 * Only permissions for the account owner.  
	 * 
	 * @see ContentDataObject::addToSharingTable()
	 */
	function addToSharingTable() {	
		parent::addToSharingTable();
		$id = $this->getId();
		
		if(!$this->getAccount() instanceof MailAccount) return;
		
		$macs = MailAccountContacts::instance()->getByAccount($this->getAccount());
		foreach ($macs as $mac) {
		
			$contactId = $mac->getContactId();
			$contact = Contacts::instance()->findById($contactId);
			
			if (!$contact instanceof Contact) continue;
			
			$group_id = $contact->getPermissionGroupId();
			if ($group_id) {
				$sql = "INSERT INTO ".TABLE_PREFIX."sharing_table ( object_id, group_id ) VALUES ('$id','$group_id') ON DUPLICATE KEY UPDATE group_id = group_id ";
				DB::execute($sql);
			}
			
		}
	}
Ejemplo n.º 3
0
	/**
	 * Returns a list of emails according to the requested parameters
	 *
	 * @param string $tag
	 * @param array $attributes
	 * @param Project $project
	 * @return array
	 */
	function getEmails($account_id = null, $state = null, $read_filter = "", $classif_filter = "", $context = null, $start = null, $limit = null, $order_by = 'received_date', $dir = 'ASC', $join_params = null, $archived = false) {
		$mailTablePrefix = "e";
		if (!$limit) $limit = user_config_option('mails_per_page') ? user_config_option('mails_per_page') : config_option('files_per_page');
		$accountConditions = "";
		// Check for accounts
		$accountConditions = '';
		if (isset($account_id) && $account_id > 0) { //Single account
			$accountConditions = " AND $mailTablePrefix.account_id = " . DB::escape($account_id);
		} else {
			// show emails from other accounts
			$macs = MailAccountContacts::instance()->getByContact(logged_user());
			$acc_ids = array(0);
			foreach ($macs as $mac) $acc_ids[] = $mac->getAccountId();
			
			// permission conditions
			$pgs = ContactPermissionGroups::getPermissionGroupIdsByContactCSV(logged_user()->getId());
			if (trim($pgs == '')) $pgs = '0';
			$perm_sql = "(SELECT count(*) FROM ".TABLE_PREFIX."sharing_table st WHERE st.object_id = $mailTablePrefix.object_id AND st.group_id IN ($pgs)) > 0";
			
			// show mails for all visible accounts and classified mails where logged_user has permissions
			$accountConditions = " AND ($mailTablePrefix.account_id IN (" . implode(",", $acc_ids) . ") OR $perm_sql)";
		}
		
		// Check for unclassified emails
		$classified = '';
		if ($classif_filter != '' && $classif_filter != 'all') {
			$classified = "AND " . ($classif_filter == 'unclassified' ? "NOT " : "");
			$classified .= "o.id IN (SELECT object_id FROM ".TABLE_PREFIX."object_members)";
		}

		// Check for draft, junk, etc. emails
		if ($state == "draft") {
			$stateConditions = " $mailTablePrefix.state = '2'";
		} else if ($state == "sent") {
			$stateConditions = " $mailTablePrefix.state IN ('1','3','5')";
		} else if ($state == "received") {
			$stateConditions = " $mailTablePrefix.state IN ('0','5')";
		} else if ($state == "junk") {
			$stateConditions = " $mailTablePrefix.state = '4'";
		} else if ($state == "outbox") {
			$stateConditions = " $mailTablePrefix.state >= 200";
		} else {
			$stateConditions = "";
		}
		
		// Check read emails
		if ($read_filter != "" && $read_filter != "all") {
			if ($read_filter == "unread") {
				$read = "AND NOT ";
				$subread = "AND NOT mc.";
			} else {
				$read = "AND ";
				$subread = "AND mc."; 
			}
			$read2 = "id IN (SELECT rel_object_id FROM " . TABLE_PREFIX . "read_objects t WHERE contact_id = " . logged_user()->getId() . "  AND t.is_read = '1')";
			$read .= $read2;
			$subread .= $read2;
		} else {
			$read = "";
			$subread = "";
		}

		
		
		// Conversations not allowed yet
		//if (user_config_option('show_emails_as_conversations')) {
		//	$state_conv_cond_1 = $state != 'received' ? " $stateConditions AND " : " m.state <> '2' AND ";
		//	$state_conv_cond_2 = $state != 'received' ? " AND (mc.state = '1' OR mc.state = '3' OR mc.state = '5') " : " AND mc.state <> '2' ";
		//	$archived_by_id = $archived ? "AND o.archived_by_id != 0" : "AND o.archived_by_id = 0";
		//	$trashed_by_id = "AND o.trashed_by_id = 0";
		//	$conversation_cond = "AND IF(m.conversation_id = 0, $stateConditions, $state_conv_cond_1 NOT EXISTS (SELECT * FROM ".TABLE_PREFIX."mail_contents mc WHERE m.conversation_id = mc.conversation_id AND m.account_id = mc.account_id AND m.received_date < mc.received_date $archived_by_id AND mc.is_deleted = 0 $trashed_by_id $subread $state_conv_cond_2))";
		//	$box_cond = "AND IF(EXISTS(SELECT * FROM ".TABLE_PREFIX."mail_contents mc WHERE m.conversation_id = mc.conversation_id AND m.object_id <> o.id AND m.account_id = mc.account_id $archived_by_id AND mc.is_deleted = 0 $trashed_by_id AND $stateConditions), TRUE, $stateConditions)";
		//} else {
			$conversation_cond = "";
			$box_cond = "AND $stateConditions";
		//}

		/*return self::findByContext(array('limit' => $limit, 'offset' => $start, 'order' => "$order_by $dir",
			'extra_conditions' => "$accountConditions $classified $read $conversation_cond $box_cond")); */

		return self::instance()->listing(array(
			'limit' => $limit, 
			'start' => $start, 
			'order' => $order_by,
			'order_dir' => $dir,
			'extra_conditions' => "$accountConditions $classified $read $conversation_cond $box_cond",
			//'count_results' => false,
			'join_params' => $join_params
		));
		
		
		
	}
	/**
	 * Return manager instance
	 *
	 * @access protected
	 * @param void
	 * @return MailAccountContacts
	 */
	function manager() {
		if(!($this->manager instanceof MailAccountContacts)) $this->manager = MailAccountContacts::instance();
		return $this->manager;
	}
 function check_account_errors()
 {
     ajx_current("empty");
     $user = logged_user();
     if (!$user instanceof Contact) {
         return;
     }
     $acc_users = MailAccountContacts::instance()->getByContact(logged_user());
     foreach ($acc_users as $acc_user) {
         /* @var $acc_user MailAccountContact */
         if ($acc_user->getLastErrorState() == MailAccountContacts::MA_ERROR_UNREAD) {
             $account = $acc_user->getAccount();
             if (!$account instanceof MailAccount) {
                 continue;
             }
             flash_error($account->getLastErrorMsg());
             $acc_user->setLastErrorState(MailAccountContacts::MA_ERROR_READ);
             $acc_user->save();
         }
     }
 }
	/**
	 * 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, 'MailAccountContacts')) {
			return parent::paginate($arguments, $items_per_page, $current_page);
		} else {
			return MailAccountContacts::instance()->paginate($arguments, $items_per_page, $current_page);
			//$instance =& MailAccounts::instance();
			//return $instance->paginate($arguments, $items_per_page, $current_page);
		} // if
	} // paginate
Ejemplo n.º 7
0
 /**
  * Returns a list of emails according to the requested parameters
  *
  * @param string $tag
  * @param array $attributes
  * @param Project $project
  * @return array
  */
 function getEmails($account_id = null, $state = null, $read_filter = "", $classif_filter = "", $context = null, $start = null, $limit = null, $order_by = 'received_date', $dir = 'ASC', $archived = false)
 {
     $mailTablePrefix = "e";
     $accountConditions = "";
     // Check for accounts
     $accountConditions = '';
     if (isset($account_id) && $account_id > 0) {
         //Single account
         $accountConditions = " AND {$mailTablePrefix}.account_id = " . DB::escape($account_id);
         /*		} else {
         			// show emails from other accounts
         			$macs = MailAccountContacts::instance()->getByContact(logged_user());
         			$acc_ids = array();
         			foreach ($macs as $mac) $acc_ids[] = $mac->getAccountId();
         			if (count($acc_ids) == 0) $acc_ids[] = 0;
         			$accountConditions = " AND $mailTablePrefix.account_id IN (" . implode(",", $acc_ids) . ")";
         */
     }
     // Check for unclassified emails
     $classified = '';
     if ($classif_filter != '' && $classif_filter != 'all') {
         if ($classif_filter == 'unclassified') {
             $classified = "AND NOT ";
         } else {
             $classified = "AND ";
         }
         $classified .= "o.id IN (SELECT object_id FROM " . TABLE_PREFIX . "object_members)";
     } else {
         if (isset($account_id) && $account_id > 0) {
             $acc_cond = "IN ({$account_id})";
         } else {
             $macs = MailAccountContacts::instance()->getByContact(logged_user());
             $acc_ids = array(0);
             foreach ($macs as $mac) {
                 $acc_ids[] = $mac->getAccountId();
             }
             $acc_cond = "IN (" . implode(",", $acc_ids) . ")";
         }
         $classified = "AND (e.account_id {$acc_cond} OR o.id IN (SELECT object_id FROM " . TABLE_PREFIX . "object_members))";
     }
     // Check for draft, junk, etc. emails
     if ($state == "draft") {
         $stateConditions = " {$mailTablePrefix}.state = '2'";
     } else {
         if ($state == "sent") {
             $stateConditions = " {$mailTablePrefix}.state IN ('1','3','5')";
         } else {
             if ($state == "received") {
                 $stateConditions = " {$mailTablePrefix}.state IN ('0','5')";
             } else {
                 if ($state == "junk") {
                     $stateConditions = " {$mailTablePrefix}.state = '4'";
                 } else {
                     if ($state == "outbox") {
                         $stateConditions = " {$mailTablePrefix}.state >= 200";
                     } else {
                         $stateConditions = "";
                     }
                 }
             }
         }
     }
     // Check read emails
     if ($read_filter != "" && $read_filter != "all") {
         if ($read_filter == "unread") {
             $read = "AND NOT ";
             $subread = "AND NOT mc.";
         } else {
             $read = "AND ";
             $subread = "AND mc.";
         }
         $read2 = "id IN (SELECT rel_object_id FROM " . TABLE_PREFIX . "read_objects t WHERE contact_id = " . logged_user()->getId() . "  AND t.is_read = '1')";
         $read .= $read2;
         $subread .= $read2;
     } else {
         $read = "";
         $subread = "";
     }
     // Conversations not allowed yet
     //if (user_config_option('show_emails_as_conversations')) {
     //	$state_conv_cond_1 = $state != 'received' ? " $stateConditions AND " : " m.state <> '2' AND ";
     //	$state_conv_cond_2 = $state != 'received' ? " AND (mc.state = '1' OR mc.state = '3' OR mc.state = '5') " : " AND mc.state <> '2' ";
     //	$archived_by_id = $archived ? "AND o.archived_by_id != 0" : "AND o.archived_by_id = 0";
     //	$trashed_by_id = "AND o.trashed_by_id = 0";
     //	$conversation_cond = "AND IF(m.conversation_id = 0, $stateConditions, $state_conv_cond_1 NOT EXISTS (SELECT * FROM ".TABLE_PREFIX."mail_contents mc WHERE m.conversation_id = mc.conversation_id AND m.account_id = mc.account_id AND m.received_date < mc.received_date $archived_by_id AND mc.is_deleted = 0 $trashed_by_id $subread $state_conv_cond_2))";
     //	$box_cond = "AND IF(EXISTS(SELECT * FROM ".TABLE_PREFIX."mail_contents mc WHERE m.conversation_id = mc.conversation_id AND m.object_id <> o.id AND m.account_id = mc.account_id $archived_by_id AND mc.is_deleted = 0 $trashed_by_id AND $stateConditions), TRUE, $stateConditions)";
     //} else {
     $conversation_cond = "";
     $box_cond = "AND {$stateConditions}";
     //}
     /*return self::findByContext(array('limit' => $limit, 'offset' => $start, 'order' => "$order_by $dir",
     		'extra_conditions' => "$accountConditions $classified $read $conversation_cond $box_cond")); */
     return self::instance()->listing(array('limit' => $limit, 'start' => $start, 'order' => $order_by, 'order_dir' => $dir, 'extra_conditions' => "{$accountConditions} {$classified} {$read} {$conversation_cond} {$box_cond}", 'count_results' => false));
 }