/** * Resolve action to perform * * @param string $action * @param array $attributes * @return string $message */ private function resolveAction($action, $attributes) { $resultMessage = ""; $resultCode = 0; switch ($action) { case "delete": $err = 0; $succ = 0; for ($i = 0; $i < count($attributes["ids"]); $i++) { $id = $attributes["ids"][$i]; $type = $attributes["types"][$i]; switch ($type) { case "email": $email = MailContents::findById($id); if (isset($email) && $email->canDelete(logged_user())) { if ($email->getState() == 2) { // we are deleting a draft email $emails_in_conversation = array($email); } else { if (user_config_option('show_emails_as_conversations', true, logged_user()->getId())) { $emails_in_conversation = MailContents::getMailsFromConversation($email); } else { $emails_in_conversation = array($email); } } foreach ($emails_in_conversation as $email) { if ($email->canDelete(logged_user())) { try { $email->trash(); ApplicationLogs::createLog($email, $email->getWorkspaces(), ApplicationLogs::ACTION_TRASH); $succ++; } catch (Exception $e) { $err++; } } else { $err++; } } } else { $err++; } break; default: $err++; break; } // switch } // for if ($err > 0) { $resultCode = 2; $resultMessage = lang("error delete objects", $err) . "<br />" . ($succ > 0 ? lang("success delete objects", $succ) : ""); } else { $resultMessage = lang("success delete objects", $succ); } ajx_add("overview-panel", "reload"); break; case "tag": $tag = $attributes["tag"]; if (!trim($tag)) { break; } for ($i = 0; $i < count($attributes["ids"]); $i++) { $id = $attributes["ids"][$i]; $type = $attributes["types"][$i]; switch ($type) { case "email": $email = MailContents::findById($id); if (isset($email)) { if (user_config_option('show_emails_as_conversations', true, logged_user()->getId())) { $emails_in_conversation = MailContents::getMailsFromConversation($email); } else { $emails_in_conversation = array($email); } foreach ($emails_in_conversation as $email) { if ($email->canEdit(logged_user())) { Tags::addObjectTag($tag, $email); ApplicationLogs::createLog($email, $email->getWorkspaces(), ApplicationLogs::ACTION_TAG, false, null, true, $tag); } } $resultMessage = lang("success tag objects", ''); } break; default: $resultMessage = lang("Unimplemented type: '" . $type . "'"); // if $resultCode = 2; break; } // switch } // for break; case "untag": $tag = $attributes["tag"]; for ($i = 0; $i < count($attributes["ids"]); $i++) { $id = $attributes["ids"][$i]; $type = $attributes["types"][$i]; switch ($type) { case "email": $email = MailContents::findById($id); if (isset($email)) { if (user_config_option('show_emails_as_conversations', true, logged_user()->getId())) { $emails_in_conversation = MailContents::getMailsFromConversation($email); } else { $emails_in_conversation = array($email); } foreach ($emails_in_conversation as $email) { if ($email->canEdit(logged_user())) { if ($tag != '') { $email->deleteTag($tag); } else { $email->clearTags(); } } } //ApplicationLogs::createLog($email, $email->getWorkspaces(), ApplicationLogs::ACTION_TAG,false,null,true,$tag); $resultMessage = lang("success untag objects", ''); } break; default: $resultMessage = lang("Unimplemented type: '" . $type . "'"); // if $resultCode = 2; break; } // switch } // for break; case "unclassify": for ($i = 0; $i < count($attributes["ids"]); $i++) { $id = $attributes["ids"][$i]; $type = $attributes["types"][$i]; switch ($type) { case "email": $email = MailContents::findById($id); if (isset($email) && !$email->isDeleted() && $email->canEdit(logged_user())) { $this->do_unclassify($email); ApplicationLogs::createLog($email, $email->getWorkspaces(), ApplicationLogs::ACTION_TAG, false, null, true, $tag); $resultMessage = lang("success unclassify emails", count($attributes["ids"])); } break; default: $resultMessage = lang("Unimplemented type: '" . $type . "'"); // if $resultCode = 2; break; } // switch } // for break; case "move": $wsid = $attributes["moveTo"]; $destination = Projects::findById($wsid); if (!$destination instanceof Project) { $resultMessage = lang('project dnx'); $resultCode = 1; } else { if (!can_add(logged_user(), $destination, 'MailContents')) { $resultMessage = lang('no access permissions'); $resultCode = 1; } else { $count = 0; for ($i = 0; $i < count($attributes["ids"]); $i++) { $id = $attributes["ids"][$i]; $type = $attributes["types"][$i]; switch ($type) { case "email": $email = MailContents::findById($id); if (user_config_option('show_emails_as_conversations', true, logged_user()->getId())) { $conversation = MailContents::getMailsFromConversation($email); } else { $conversation = array($email); } foreach ($conversation as $conv_email) { $this->addEmailToWorkspace($conv_email->getId(), $destination, array_var($attributes, "mantainWs", true)); if (array_var($attributes, 'classify_atts') && $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; } $tags = implode(",", $conv_email->getTagNames()); $this->classifyFile($classification_data, $conv_email, $parsedEmail, array($destination), array_var($attributes, "mantainWs", true), $tags); } } $count++; break; default: $resultMessage = lang("Unimplemented type: '" . $type . "'"); // if $resultCode = 2; break; } // switch } // for $resultMessage = lang("success move objects", $count); $resultCode = 0; } } break; case "checkmail": $resultCheck = MailController::checkmail(); $resultMessage = $resultCheck[1]; // if $resultCode = $resultCheck[0]; ajx_add("overview-panel", "reload"); break; case "markAsRead": case "markAsUnRead": for ($i = 0; $i < count($attributes["ids"]); $i++) { $id = $attributes["ids"][$i]; $type = $attributes["types"][$i]; switch ($type) { case "email": $email = MailContents::findById($id); if (isset($email)) { if (user_config_option('show_emails_as_conversations', true, logged_user()->getId())) { $emails_in_conversation = MailContents::getMailsFromConversation($email); } else { $emails_in_conversation = array($email); } foreach ($emails_in_conversation as $email) { if ($email->canEdit(logged_user())) { $email->setIsRead(logged_user()->getId(), $action == 'markAsRead'); } } } break; default: $resultMessage = lang("Unimplemented type: '" . $type . "'"); // if $resultCode = 2; break; } // switch } // for ajx_add("overview-panel", "reload"); break; case "archive": $err = 0; $succ = 0; for ($i = 0; $i < count($attributes["ids"]); $i++) { $id = $attributes["ids"][$i]; $type = $attributes["types"][$i]; switch ($type) { case "email": $email = MailContents::findById($id); if (isset($email)) { if (user_config_option('show_emails_as_conversations', true, logged_user()->getId())) { $emails_in_conversation = MailContents::getMailsFromConversation($email); } else { $emails_in_conversation = array($email); } foreach ($emails_in_conversation as $email) { if ($email->canEdit(logged_user())) { try { $email->archive(null); ApplicationLogs::createLog($email, $email->getWorkspaces(), ApplicationLogs::ACTION_ARCHIVE); $succ++; } catch (Exception $e) { $err++; } } } } else { $err++; } break; default: $err++; break; } // switch } // for if ($err > 0) { $resultCode = 2; $resultMessage = lang("error archive objects", $err) . "<br />" . ($succ > 0 ? lang("success archive objects", $succ) : ""); } else { $resultMessage = lang("success archive objects", $succ); } ajx_add("overview-panel", "reload"); break; default: if ($action) { $resultMessage = lang("Unimplemented action: '" . $action . "'"); // if $resultCode = 2; } break; } // switch return array("errorMessage" => $resultMessage, "errorCode" => $resultCode); }
/** * Resolve action to perform * * @param string $action * @param array $attributes * @return string $message */ private function resolveAction($action, $attributes) { $resultMessage = ""; $resultCode = 0; switch ($action) { case "delete": $err = 0; $succ = 0; for ($i = 0; $i < count($attributes["ids"]); $i++) { $id = $attributes["ids"][$i]; $type = $attributes["types"][$i]; switch ($type) { case "email": $email = MailContents::findById($id); if ($email instanceof MailContent && $email->canDelete(logged_user())) { if ($email->getState() == 2) { // we are deleting a draft email $emails_in_conversation = array($email); } else { if (user_config_option('show_emails_as_conversations', true, logged_user()->getId())) { $emails_in_conversation = MailContents::getMailsFromConversation($email); } else { $emails_in_conversation = array($email); } } foreach ($emails_in_conversation as $email) { if ($email->canDelete(logged_user())) { try { $email->trash(); ApplicationLogs::createLog($email, $email->getWorkspaces(), ApplicationLogs::ACTION_TRASH); $succ++; } catch (Exception $e) { $err++; } } else { $err++; } } } else { $err++; } break; default: $err++; break; } // switch } // for if ($err > 0) { $resultCode = 2; $resultMessage = lang("error delete objects", $err) . "<br />" . ($succ > 0 ? lang("success delete objects", $succ) : ""); } else { $resultMessage = lang("success delete objects", $succ); } ajx_add("overview-panel", "reload"); break; case "unclassify": for ($i = 0; $i < count($attributes["ids"]); $i++) { $id = $attributes["ids"][$i]; $type = $attributes["types"][$i]; switch ($type) { case "email": $email = MailContents::findById($id); if (isset($email) && !$email->isDeleted() && $email->canEdit(logged_user())) { $this->do_unclassify($email); ApplicationLogs::createLog($email, $email->getWorkspaces(), ApplicationLogs::ACTION_TAG, false, null, true, $tag); $resultMessage = lang("success unclassify emails", count($attributes["ids"])); } break; default: $resultMessage = "Unimplemented type: '" . $type . "'"; $resultCode = 2; break; } // switch } // for break; case "checkmail": $resultCheck = MailController::checkmail(); $resultMessage = $resultCheck[1]; // if $resultCode = $resultCheck[0]; ajx_add("overview-panel", "reload"); break; case "markAsRead": case "markAsUnRead": for ($i = 0; $i < count($attributes["ids"]); $i++) { $id = $attributes["ids"][$i]; $type = $attributes["types"][$i]; switch ($type) { case "email": $email = MailContents::findById($id); if (isset($email)) { if (user_config_option('show_emails_as_conversations', true, logged_user()->getId())) { $emails_in_conversation = MailContents::getMailsFromConversation($email); } else { $emails_in_conversation = array($email); } foreach ($emails_in_conversation as $email) { if ($email->canEdit(logged_user())) { $email->setIsRead(logged_user()->getId(), $action == 'markAsRead'); } } } break; default: $resultMessage = "Unimplemented type: '" . $type . "'"; $resultCode = 2; break; } // switch } // for ajx_add("overview-panel", "reload"); break; case "archive": $err = 0; $succ = 0; for ($i = 0; $i < count($attributes["ids"]); $i++) { $id = $attributes["ids"][$i]; $type = $attributes["types"][$i]; switch ($type) { case "email": $email = MailContents::findById($id); if (isset($email)) { if (user_config_option('show_emails_as_conversations', true, logged_user()->getId())) { $emails_in_conversation = MailContents::getMailsFromConversation($email); } else { $emails_in_conversation = array($email); } foreach ($emails_in_conversation as $email) { if ($email->canEdit(logged_user())) { try { $email->archive(null); ApplicationLogs::createLog($email, $email->getWorkspaces(), ApplicationLogs::ACTION_ARCHIVE); $succ++; } catch (Exception $e) { $err++; } } } } else { $err++; } break; default: $err++; break; } // switch } // for if ($err > 0) { $resultCode = 2; $resultMessage = lang("error archive objects", $err) . "<br />" . ($succ > 0 ? lang("success archive objects", $succ) : ""); } else { $resultMessage = lang("success archive objects", $succ); } ajx_add("overview-panel", "reload"); break; default: if ($action) { $resultMessage = "Unimplemented action: '" . $action . "'"; $resultCode = 2; } break; } // switch return array("errorMessage" => $resultMessage, "errorCode" => $resultCode); }