Пример #1
0
function mail_do_mark_as_read_unread_objects($ids_to_mark, $read)
{
    $all_accounts = array();
    $all_accounts_ids = array();
    foreach ($ids_to_mark as $id) {
        $obj = Objects::findObject($id);
        if ($obj instanceof MailContent && logged_user() instanceof Contact) {
            //conversation set the rest of the conversation
            $uds_to_mark_from_conver = array();
            if (user_config_option('show_emails_as_conversations')) {
                $emails_in_conversation = MailContents::getMailsFromConversation($obj);
                foreach ($emails_in_conversation as $email) {
                    //$id is marked on object controller only mark the rest of the conversation
                    if ($id != $email->getId()) {
                        $email->setIsRead(logged_user()->getId(), $read);
                        $uds_to_mark_from_conver[] = $email->getUid();
                    }
                }
            }
            //make the array with accounts and uids to send to the mail server
            //accounts
            if (!in_array($obj->getAccountId(), $all_accounts_ids)) {
                $account = $obj->getAccount();
                //if logged user is owner of this account and is imap
                if ($account instanceof MailAccount && $account->getContactId() == logged_user()->getId() && $account->getIsImap()) {
                    $all_accounts_ids[] = $obj->getAccountId();
                    $all_accounts[$account->getId()]['account'] = $account;
                }
            }
            //uids
            if (in_array($obj->getAccountId(), $all_accounts_ids)) {
                //add conversations uids
                //mientras ande mal el uid de los mails enviados si estan sincronizados no usar esta parte
                /*if (user_config_option('show_emails_as_conversations')) {
                			foreach ($uds_to_mark_from_conver as $uid_conver){
                				$all_accounts[$obj->getAccountId()]['uids'][] = $uid_conver;
                			}
                		}*/
                $all_accounts[$obj->getAccountId()]['folders'][$obj->getImapFolderName()][] = $obj->getUid();
            }
        }
    }
    //foreach account send uids by folder to mark in the mail server
    foreach ($all_accounts as $account_data) {
        $account = $account_data['account'];
        $folders = $account_data['folders'];
        foreach ($folders as $key => $folder) {
            $folder_name = $key;
            $uids = $folder;
            if (!empty($folder_name)) {
                try {
                    MailUtilities::setReadUnreadImapMails($account, $folder_name, $uids, $read);
                } catch (Exception $e) {
                    Logger::log("Could not set mail as read on mail server, exception:\n" . $e->getMessage());
                }
            }
        }
    }
}
Пример #2
0
	function getLinkedObjects() {
		$conv_emails = MailContents::getMailsFromConversation($this);
		$objects = array();
		foreach ($conv_emails as $mail){
			if(logged_user()->isMemberOfOwnerCompany()) {
				$mail_objects = $mail->getAllLinkedObjects();
			} else {
				if (is_null($mail->linked_objects)) {
					$mail->linked_objects = LinkedObjects::getLinkedObjectsByObject($this, true);
				}
				$mail_objects = $mail->linked_objects;
			}
			if (is_array($mail_objects)){
				foreach ($mail_objects as $mo){
					$objects[] = $mo;
				}
			}
		}
		
		if ($this->isTrashed()) {
			$include_trashed = true;
		} else {
			$include_trashed = false;
		}
		
		if ($include_trashed) {
			return $objects;
		} else {
			$ret = array();
			if (is_array($objects) && count($objects)) {
				foreach ($objects as $o) {
					if (!$o instanceof ContentDataObject || !$o->isTrashed()) {
						$ret[] = $o;
					}
				}
			}
			return $ret;
		}
	}
Пример #3
0
					$icon = "unknown.png";
				$download_url = get_url('mail', 'download_attachment', array('email_id' => $email->getId(), 'attachment_id' => $c));
				include_once ROOT . "/library/browser/Browser.php";
				if (Browser::instance()->getBrowser() == Browser::BROWSER_IE) {
					$download_url = "javascript:location.href = '$download_url';";
				}
	      		$description .=	'<img src="' . get_image_url("filetypes/" . $icon) .'"></td>
				<td><a target="_self" href="' . $download_url . '">' . clean($fName) . " ($size)" . '</a></td></tr>';
			}
      		$c++;
		}
		$description .= '</table></div></fieldset></td></tr>';
  } //if
  $description .= '</table></div>';
		if (($email_count = MailContents::countMailsInConversation($email)) > 1) {
			$emails_info = MailContents::getMailsFromConversation($email);
			$conversation_block = '';
			$conversation_block .= '<div id="'.$genid.'conversation" style="margin-bottom:10px;' . 
				(count($emails_info) > 6 ? 'max-height:101px;overflow:auto' : ''  ) . '"><table style="width:100%;">';
			
			$unread = 0;
			foreach($emails_info as $count => $info) { 
				$row_cls = $count % 2 ? 'odd' : 'even';
				$is_current = $info->getId() == $email->getId();
				$style = $is_current ? "style='background-color:#FFDD78'" : "";
				$conversation_block .= '<tr class="'.$row_cls.'" ' . $style . '>';
				
				$state = $info->getState();
				$show_user_icon = false;
				if ($state == 1 || $state == 3 || $state == 5) {
					if ($info->getCreatedById() == logged_user()->getId()) {
    /**
     * Used for Drag & Drop, adds objects to a member
     * @author alvaro
     */
    function add_objects_to_member()
    {
        $ids = json_decode(array_var($_POST, 'objects'));
        $mem_id = array_var($_POST, 'member');
        if (!is_array($ids) || count($ids) == 0) {
            ajx_current("empty");
            return;
        }
        try {
            DB::beginWork();
            if ($mem_id) {
                $user_ids = array();
                $member = Members::findById($mem_id);
                $objects = array();
                $from = array();
                foreach ($ids as $oid) {
                    /* @var $obj ContentDataObject */
                    $obj = Objects::findObject($oid);
                    if ($obj instanceof ContentDataObject && $obj->canAddToMember(logged_user(), $member, active_context())) {
                        $dim_obj_type_content = DimensionObjectTypeContents::findOne(array('conditions' => array('`dimension_id`=? AND `dimension_object_type_id`=? AND `content_object_type_id`=?', $member->getDimensionId(), $member->getObjectTypeId(), $obj->getObjectTypeId())));
                        if (!$dim_obj_type_content instanceof DimensionObjectTypeContent) {
                            continue;
                        }
                        if (!$dim_obj_type_content->getIsMultiple() || array_var($_POST, 'remove_prev')) {
                            $db_res = DB::execute("SELECT group_concat(om.member_id) as old_members FROM " . TABLE_PREFIX . "object_members om INNER JOIN " . TABLE_PREFIX . "members m ON om.member_id=m.id WHERE m.dimension_id=" . $member->getDimensionId() . " AND om.object_id=" . $obj->getId());
                            $row = $db_res->fetchRow();
                            if (array_var($row, 'old_members') != "") {
                                $from[$obj->getId()] = $row['old_members'];
                            }
                            // remove from previous members
                            ObjectMembers::delete('`object_id` = ' . $obj->getId() . ' AND `member_id` IN (SELECT `m`.`id` FROM `' . TABLE_PREFIX . 'members` `m` WHERE `m`.`dimension_id` = ' . $member->getDimensionId() . ')');
                        }
                        $obj->addToMembers(array($member));
                        $obj->addToSharingTable();
                        $objects[] = $obj;
                        if (Plugins::instance()->isActivePlugin('mail') && $obj instanceof MailContent) {
                            $conversation = MailContents::getMailsFromConversation($obj);
                            foreach ($conversation as $conv_email) {
                                if (array_var($_POST, 'attachment') && $conv_email->getHasAttachments()) {
                                    MailUtilities::parseMail($conv_email->getContent(), $decoded, $parsedEmail, $warnings);
                                    $classification_data = array();
                                    for ($j = 0; $j < count(array_var($parsedEmail, "Attachments", array())); $j++) {
                                        $classification_data["att_" . $j] = true;
                                    }
                                    MailController::classifyFile($classification_data, $conv_email, $parsedEmail, array($member), array_var($_POST, 'remove_prev'), false);
                                }
                            }
                        }
                        // if object is contact ask to add default permissions in member
                        if ($obj instanceof Contact && $obj->isUser() && can_manage_security(logged_user())) {
                            $user_ids[] = $obj->getId();
                        }
                    } else {
                        throw new Exception(lang('you dont have permissions to classify object in member', $obj->getName(), $member->getName()));
                    }
                }
                // if object is contact ask to add default permissions in member
                if (can_manage_security(logged_user()) && count($user_ids) > 0 && $member->getDimension()->getDefinesPermissions()) {
                    evt_add('ask to assign default permissions', array('user_ids' => $user_ids, 'member' => array('id' => $member->getId(), 'name' => clean($member->getName())), ''));
                }
                Hook::fire('after_dragdrop_classify', $objects, $member);
                $display_name = $member->getName();
                $lang_key = count($ids) > 1 ? 'objects moved to member success' : 'object moved to member success';
                $log_datas = array();
                $actions = array();
                // add to application logs
                foreach ($objects as $obj) {
                    $actions[$obj->getId()] = array_var($from, $obj->getId()) ? ApplicationLogs::ACTION_MOVE : ApplicationLogs::ACTION_COPY;
                    $log_datas[$obj->getId()] = (array_var($from, $obj->getId()) ? "from:" . array_var($from, $obj->getId()) . ";" : "") . "to:" . $member->getId();
                }
            } else {
                if ($dim_id = array_var($_POST, 'dimension')) {
                    $dimension = Dimensions::getDimensionById($dim_id);
                    $from = array();
                    foreach ($ids as $oid) {
                        /* @var $obj ContentDataObject */
                        $obj = Objects::findObject($oid);
                        if ($obj instanceof ContentDataObject) {
                            $db_res = DB::execute("SELECT group_concat(om.member_id) as old_members FROM " . TABLE_PREFIX . "object_members om INNER JOIN " . TABLE_PREFIX . "members m ON om.member_id=m.id WHERE m.dimension_id=" . $dim_id . " AND om.object_id=" . $obj->getId());
                            $row = $db_res->fetchRow();
                            if (array_var($row, 'old_members') != "") {
                                $from[$obj->getId()] = $row['old_members'];
                            }
                            // remove from previous members
                            ObjectMembers::delete('`object_id` = ' . $obj->getId() . ' AND `member_id` IN (
							SELECT `m`.`id` FROM `' . TABLE_PREFIX . 'members` `m` WHERE `m`.`dimension_id` = ' . $dim_id . ')');
                        }
                        $obj->addToMembers(array());
                        $obj->addToSharingTable();
                        $objects[] = $obj;
                    }
                    $display_name = $dimension->getName();
                    $lang_key = count($ids) > 1 ? 'objects removed from' : 'object removed from';
                    $log_datas = array();
                    $actions = array();
                    // add to application logs
                    foreach ($objects as $obj) {
                        $actions[$obj->getId()] = array_var($from, $obj->getId()) ? ApplicationLogs::ACTION_MOVE : ApplicationLogs::ACTION_COPY;
                        $log_datas[$obj->getId()] = array_var($from, $obj->getId()) ? "from:" . array_var($from, $obj->getId()) . ";" : "";
                    }
                }
            }
            DB::commit();
            foreach ($objects as $object) {
                ApplicationLogs::instance()->createLog($object, $actions[$object->getId()], false, true, true, $log_datas[$object->getId()]);
            }
            flash_success(lang($lang_key, $display_name));
            if (array_var($_POST, 'reload')) {
                ajx_current('reload');
            } else {
                ajx_current('empty');
            }
        } catch (Exception $e) {
            DB::rollback();
            ajx_current("empty");
            flash_error($e->getMessage());
        }
    }
Пример #5
0
 function do_mark_as_read_unread_objects($ids, $read, $mark_conversation = false)
 {
     $err = 0;
     // count errors
     $succ = 0;
     // count updated objects
     foreach ($ids as $id) {
         try {
             $obj = Objects::findObject($id);
             if ($obj instanceof ContentDataObject && logged_user() instanceof Contact) {
                 $obj->setIsRead(logged_user()->getId(), $read);
                 if (Plugins::instance()->isActivePlugin('mail')) {
                     if ($obj instanceof MailContent && $mark_conversation) {
                         $emails_in_conversation = MailContents::getMailsFromConversation($obj);
                         foreach ($emails_in_conversation as $email) {
                             $email->setIsRead(logged_user()->getId(), $read);
                         }
                     }
                 }
             }
             $succ++;
         } catch (Exception $e) {
             $err++;
         }
         // try
     }
     return array($succ, $err);
 }
 function get_conversation_info()
 {
     $email = MailContents::findById(array_var($_GET, 'id'));
     if (!$email instanceof MailContent) {
         flash_error(lang('email dnx'));
         ajx_current("empty");
         return;
     }
     $info = array();
     $mails = MailContents::getMailsFromConversation($email);
     foreach ($mails as $mail) {
         $text = $mail->getBodyPlain();
         if (strlen_utf($text) > 80) {
             $text = substr_utf($text, 0, 80) . "...";
         }
         $state = $mail->getState();
         $show_user_icon = false;
         if ($state == 1 || $state == 3 || $state == 5) {
             if ($mail->getCreatedById() == logged_user()->getId()) {
                 $from = lang('you');
             } else {
                 $from = $mail->getCreatedByDisplayName();
             }
             $show_user_icon = true;
         } else {
             $from = $mail->getFrom();
         }
         $info[] = array('id' => $mail->getId(), 'date' => $mail->getReceivedDate() instanceof DateTimeValue ? $mail->getReceivedDate()->isToday() ? format_time($mail->getReceivedDate()) : format_datetime($mail->getReceivedDate()) : lang('n/a'), 'has_att' => $mail->getHasAttachments(), 'text' => htmlentities($text), 'read' => $mail->getIsRead(logged_user()->getId()), 'from_name' => $state == 1 || $state == 3 || $state == 5 ? lang('you') : $mail->getFromName(), 'from' => $from, 'show_ico' => $show_user_icon);
     }
     tpl_assign('source_email_id', array_var($_GET, 'id'));
     tpl_assign('emails_info', $info);
     $this->setLayout("html");
     $this->setTemplate("llo_email_conversation");
     ajx_current("empty");
 }
 function untag()
 {
     if (logged_user()->isGuest()) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     ajx_current("empty");
     $csvids = array_var($_GET, 'ids');
     $tag = trim(array_var($_GET, 'tag', ''));
     $all = array_var($_GET, 'all');
     if (!$tag && !$all) {
         flash_error(lang("no tag specified"));
         return;
     }
     $ids = explode(",", $csvids);
     $count = 0;
     $err = 0;
     foreach ($ids as $id) {
         try {
             $parts = explode(":", $id);
             $object = get_object_by_manager_and_id($parts[1], $parts[0]);
             if ($object instanceof ProjectDataObject && $object->canEdit(logged_user())) {
                 if ($object instanceof MailContent && user_config_option('show_emails_as_conversations', true, logged_user()->getId())) {
                     $emails = MailContents::getMailsFromConversation($object);
                     foreach ($emails as $email) {
                         if ($all) {
                             $email->clearTags();
                         } else {
                             $email->deleteTag($tag);
                         }
                         ApplicationLogs::createLog($email, $email->getWorkspaces(), ApplicationLogs::ACTION_UNTAG);
                     }
                 } else {
                     if ($all) {
                         $object->clearTags();
                     } else {
                         $object->deleteTag($tag);
                     }
                     ApplicationLogs::createLog($object, $object->getWorkspaces(), ApplicationLogs::ACTION_UNTAG);
                 }
                 $count++;
             } else {
                 $err++;
             }
         } catch (Exception $e) {
             $err++;
         }
     }
     if ($err > 0) {
         flash_error(lang("error untag objects", $err));
     } else {
         flash_success(lang("success untag objects", $count));
     }
 }
Пример #8
0
	/**
	 * Used for Drag & Drop, adds objects to a member
	 * @author alvaro
	 */
	function add_objects_to_member() {
		$ids = json_decode(array_var($_POST, 'objects'));
		$mem_id = array_var($_POST, 'member');
		
		if (!is_array($ids) || count($ids) == 0) {
			ajx_current("empty");
			return;
		}
                
		$member = Members::findById($mem_id);
		
		try {
			DB::beginWork();
			
			$objects = array();
			$from = array();
			foreach ($ids as $oid) {
				/* @var $obj ContentDataObject */
				$obj = Objects::findObject($oid);
				if ($obj instanceof ContentDataObject && $obj->canAddToMember(logged_user(), $member, active_context())) {
					
					$dim_obj_type_content = DimensionObjectTypeContents::findOne(array('conditions' => array('`dimension_id`=? AND `dimension_object_type_id`=? AND `content_object_type_id`=?', $member->getDimensionId(), $member->getObjectTypeId(), $obj->getObjectTypeId())));
					if (!($dim_obj_type_content instanceof DimensionObjectTypeContent)) continue;
					if (!$dim_obj_type_content->getIsMultiple() || array_var($_POST, 'remove_prev')) {
						$db_res = DB::execute("SELECT group_concat(om.member_id) as old_members FROM ".TABLE_PREFIX."object_members om INNER JOIN ".TABLE_PREFIX."members m ON om.member_id=m.id WHERE m.dimension_id=".$member->getDimensionId()." AND om.object_id=".$obj->getId());
						$row = $db_res->fetchRow();
						if (array_var($row, 'old_members') != "") $from[$obj->getId()] = $row['old_members'];
						// remove from previous members
						ObjectMembers::delete('`object_id` = ' . $obj->getId() . ' AND `member_id` IN (SELECT `m`.`id` FROM `'.TABLE_PREFIX.'members` `m` WHERE `m`.`dimension_id` = '.$member->getDimensionId().')');
					}
					
					$obj->addToMembers(array($member));
					$obj->addToSharingTable();
					$objects[] = $obj;
					
					if ($obj->allowsTimeslots()) {
						$timeslots = $obj->getTimeslots();
						foreach ($timeslots as $timeslot) {
							$ts_mids = ObjectMembers::getMemberIdsByObject($timeslot->getId());
							// if classified then reclassify
							if (count($ts_mids)) {
								if (array_var($_POST, 'remove_prev')) {
									ObjectMembers::delete('`object_id` = ' . $timeslot->getId() . ' AND `member_id` IN (SELECT `m`.`id` FROM `'.TABLE_PREFIX.'members` `m` WHERE `m`.`dimension_id` = '.$member->getDimensionId().')');
								}
								$timeslot->addToMembers(array($member));
								$timeslot->addToSharingTable();
								$objects[] = $timeslot;
							}
						}
					}
					
					if ($obj instanceof MailContent) {
						$conversation = MailContents::getMailsFromConversation($obj);
						foreach ($conversation as $conv_email) {
							if (array_var($_POST, 'attachment') && $conv_email->getHasAttachments()) {
								MailUtilities::parseMail($conv_email->getContent(), $decoded, $parsedEmail, $warnings);
								$classification_data = array();
								for ($j=0; $j < count(array_var($parsedEmail, "Attachments", array())); $j++) {
									$classification_data["att_".$j] = true;
								}
								MailController::classifyFile($classification_data, $conv_email, $parsedEmail, array($member), array_var($_POST, 'remove_prev'));
							}
						}
					}
				} else {
					throw new Exception(lang('you dont have permissions to classify object in member', $obj->getName(), $member->getName()));
				}
			}
			
			Hook::fire('after_dragdrop_classify', $objects, $member);
			
			DB::commit();
			
			// add to application logs
			foreach ($objects as $object) {
				$action = array_var($from, $obj->getId()) ? ApplicationLogs::ACTION_MOVE : ApplicationLogs::ACTION_COPY;
				$log_data = (array_var($from, $obj->getId()) ? "from:" . array_var($from, $obj->getId()) . ";" : "") . "to:" . $member->getId();
				ApplicationLogs::instance()->createLog($object, $action, false, true, true, $log_data);
			}
			
			$lang_key = count($ids)>1 ? 'objects moved to member success' : 'object moved to member success';
			flash_success(lang($lang_key, $member->getName()));
			if (array_var($_POST, 'reload')) ajx_current('reload');
			else ajx_current('empty');
			
		} catch (Exception $e) {
			DB::rollback();
			ajx_current("empty");
			flash_error($e->getMessage());
		}
	}