예제 #1
0
 /**
  * Add comment
  *
  * Through this controller only logged users can post (no anonymous comments here)
  *
  * @param void
  * @return null
  */
 function add()
 {
     $this->setTemplate('add_comment');
     $object_id = get_id('object_id');
     $object = Objects::findObject($object_id);
     if (!$object instanceof ContentDataObject) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     // if
     $comment = new Comment();
     $comment_data = array_var($_POST, 'comment');
     tpl_assign('comment_form_object', $object);
     tpl_assign('comment', $comment);
     tpl_assign('comment_data', $comment_data);
     if (is_array($comment_data)) {
         try {
             try {
                 $attached_files = ProjectFiles::handleHelperUploads(active_context());
             } catch (Exception $e) {
                 $attached_files = null;
             }
             // try
             $comment->setFromAttributes($comment_data);
             $comment->setRelObjectId($object_id);
             $comment->setObjectName(substr_utf($comment->getText(), 0, 250));
             DB::beginWork();
             $comment->save();
             $comment->addToMembers($object->getMembers());
             if (is_array($attached_files)) {
                 foreach ($attached_files as $attached_file) {
                     $comment->attachFile($attached_file);
                 }
                 // foreach
             }
             // if
             // Subscribe user to object
             if (!$object->isSubscriber(logged_user())) {
                 $object->subscribeUser(logged_user());
             }
             // if
             if (strlen($comment->getText()) < 100) {
                 $comment_head = $comment->getText();
             } else {
                 $lastpos = strpos($comment->getText(), " ", 100);
                 if ($lastpos === false) {
                     $comment_head = $comment->getText();
                 } else {
                     $comment_head = substr($comment->getText(), 0, $lastpos) . "...";
                 }
             }
             $comment_head = html_to_text($comment_head);
             ApplicationLogs::createLog($comment, ApplicationLogs::ACTION_COMMENT, false, false, true, $comment_head);
             DB::commit();
             flash_success(lang('success add comment'));
             ajx_current("reload");
         } catch (Exception $e) {
             DB::rollback();
             ajx_current("empty");
             flash_error($e->getMessage());
         }
         // try
     }
     // if
 }
 /**
  * Add ticket
  *
  * @access public
  * @param void
  * @return null
  */
 function add_ticket()
 {
     $this->setTemplate('add_ticket');
     if (!ProjectTicket::canAdd(logged_user(), active_project())) {
         flash_error(lang('no access permissions'));
         $this->redirectToReferer(get_url('tickets'));
     }
     // if
     $ticket = new ProjectTicket();
     $ticket->setProjectId(active_project()->getId());
     $ticket_data = array_var($_POST, 'ticket');
     if (!is_array($ticket_data)) {
         $ticket_data = array('is_private' => config_option('default_private', false));
         // array
     }
     tpl_assign('ticket', $ticket);
     tpl_assign('ticket_data', $ticket_data);
     if (is_array(array_var($_POST, 'ticket'))) {
         try {
             $uploaded_files = ProjectFiles::handleHelperUploads(active_project());
         } catch (Exception $e) {
             $uploaded_files = null;
         }
         // try
         try {
             $ticket->setFromAttributes($ticket_data);
             $assigned_to = explode(':', array_var($ticket_data, 'assigned_to', ''));
             $ticket->setAssignedToCompanyId(array_var($assigned_to, 0, 0));
             $ticket->setAssignedToUserId(array_var($assigned_to, 1, 0));
             // Options are reserved only for members of owner company
             if (!logged_user()->isMemberOfOwnerCompany()) {
                 $ticket->setIsPrivate(false);
             }
             // if
             DB::beginWork();
             $ticket->save();
             if (is_array($uploaded_files)) {
                 foreach ($uploaded_files as $uploaded_file) {
                     $ticket->attachFile($uploaded_file);
                     $uploaded_file->setIsPrivate($ticket->isPrivate());
                     $uploaded_file->setIsVisible(true);
                     $uploaded_file->setExpirationTime(EMPTY_DATETIME);
                     $uploaded_file->save();
                 }
                 // if
             }
             // if
             ApplicationLogs::createLog($ticket, active_project(), ApplicationLogs::ACTION_ADD);
             DB::commit();
             // Try to send notifications but don't break submission in case of an error
             try {
                 if ($ticket->getAssignedToUserId()) {
                     $ticket_data['notify_user_' . $ticket->getAssignedToUserId()] = 'checked';
                 }
                 $notify_people = array();
                 $project_companies = active_project()->getCompanies();
                 foreach ($project_companies as $project_company) {
                     $company_users = $project_company->getUsersOnProject(active_project());
                     if (is_array($company_users)) {
                         foreach ($company_users as $company_user) {
                             if (array_var($ticket_data, 'notify_company_' . $project_company->getId()) == 'checked' || array_var($ticket_data, 'notify_user_' . $company_user->getId())) {
                                 $ticket->subscribeUser($company_user);
                                 // subscribe
                                 $notify_people[] = $company_user;
                             }
                             // if
                         }
                         // if
                     }
                     // if
                 }
                 // if
                 Notifier::ticket($ticket, $notify_people, 'new_ticket', $ticket->getCreatedBy());
             } catch (Exception $e) {
             }
             // try
             flash_success(lang('success add ticket', $ticket->getSummary()));
             $this->redirectTo('tickets');
             // Error...
         } catch (Exception $e) {
             DB::rollback();
             if (is_array($uploaded_files)) {
                 foreach ($uploaded_files as $uploaded_file) {
                     $uploaded_file->delete();
                 }
                 // foreach
             }
             // if
             $ticket->setNew(true);
             tpl_assign('error', $e);
         }
         // try
     }
     // if
 }
예제 #3
0
 /**
  * Add message
  *
  * @access public
  * @param void
  * @return null
  */
 function add()
 {
     $this->setTemplate('add_message');
     if (!ProjectMessage::canAdd(logged_user(), active_project())) {
         flash_error(lang('no access permissions'));
         $this->redirectToReferer(get_url('message'));
     }
     // if
     $message = new ProjectMessage();
     tpl_assign('message', $message);
     $message_data = array_var($_POST, 'message');
     if (!is_array($message_data)) {
         $message_data = array('milestone_id' => array_var($_GET, 'milestone_id'));
         // array
     }
     // if
     tpl_assign('message_data', $message_data);
     if (is_array(array_var($_POST, 'message'))) {
         try {
             $uploaded_files = ProjectFiles::handleHelperUploads(active_project());
         } catch (Exception $e) {
             $uploaded_files = null;
         }
         // try
         try {
             $message->setFromAttributes($message_data);
             $message->setProjectId(active_project()->getId());
             // Options are reserved only for members of owner company
             if (!logged_user()->isMemberOfOwnerCompany()) {
                 $message->setIsPrivate(false);
                 $message->setIsImportant(false);
                 $message->setCommentsEnabled(true);
                 $message->setAnonymousCommentsEnabled(false);
             }
             // if
             DB::beginWork();
             $message->save();
             $message->subscribeUser(logged_user());
             $message->setTagsFromCSV(array_var($message_data, 'tags'));
             if (is_array($uploaded_files)) {
                 foreach ($uploaded_files as $uploaded_file) {
                     $message->attachFile($uploaded_file);
                     $uploaded_file->setIsPrivate($message->isPrivate());
                     $uploaded_file->setIsVisible(true);
                     $uploaded_file->setExpirationTime(EMPTY_DATETIME);
                     $uploaded_file->save();
                 }
                 // if
             }
             // if
             ApplicationLogs::createLog($message, active_project(), ApplicationLogs::ACTION_ADD);
             DB::commit();
             // Try to send notifications but don't break submission in case of an error
             try {
                 $notify_people = array();
                 $project_companies = active_project()->getCompanies();
                 foreach ($project_companies as $project_company) {
                     $company_users = $project_company->getUsersOnProject(active_project());
                     if (is_array($company_users)) {
                         foreach ($company_users as $company_user) {
                             if (array_var($message_data, 'notify_company_' . $project_company->getId()) == 'checked' || array_var($message_data, 'notify_user_' . $company_user->getId())) {
                                 $message->subscribeUser($company_user);
                                 // subscribe
                                 $notify_people[] = $company_user;
                             }
                             // if
                         }
                         // if
                     }
                     // if
                 }
                 // if
                 Notifier::newMessage($message, $notify_people);
                 // send notification email...
             } catch (Exception $e) {
             }
             // try
             flash_success(lang('success add message', $message->getTitle()));
             $this->redirectTo('message');
             // Error...
         } catch (Exception $e) {
             DB::rollback();
             if (is_array($uploaded_files)) {
                 foreach ($uploaded_files as $uploaded_file) {
                     $uploaded_file->delete();
                 }
                 // foreach
             }
             // if
             $message->setNew(true);
             tpl_assign('error', $e);
         }
         // try
     }
     // if
 }
예제 #4
0
 /**
  * Attach files to the object
  *
  * @param void
  * @return null
  */
 function attach_to_object()
 {
     $manager_class = array_var($_GET, 'manager');
     $object_id = get_id('object_id');
     $object = get_object_by_manager_and_id($object_id, $manager_class);
     if (!$object instanceof ProjectDataObject) {
         flash_error(lang('no access permissions'));
         $this->redirectToReferer(get_url('dashboard'));
     }
     // if
     $already_attached_files = $object->getAttachedFiles();
     $already_attached_file_ids = null;
     if (is_array($already_attached_files)) {
         $already_attached_file_ids = array();
         foreach ($already_attached_files as $already_attached_file) {
             $already_attached_file_ids[] = $already_attached_file->getId();
         }
         // foreach
     }
     // if
     $attach_data = array_var($_POST, 'attach');
     if (!is_array($attach_data)) {
         $attach_data = array('what' => 'existing_file');
     }
     // if
     tpl_assign('attach_to_object', $object);
     tpl_assign('attach_data', $attach_data);
     tpl_assign('already_attached_file_ids', $already_attached_file_ids);
     if (is_array(array_var($_POST, 'attach'))) {
         $attach_files = array();
         if (array_var($attach_data, 'what') == 'existing_file') {
             $file = ProjectFiles::findById(array_var($attach_data, 'file_id'));
             if (!$file instanceof ProjectFile) {
                 flash_error(lang('no files to attach'));
                 $this->redirectToUrl($object->getAttachFilesUrl());
             }
             // if
             $attach_files[] = $file;
         } elseif (array_var($attach_data, 'what') == 'new_file') {
             try {
                 $attach_files = ProjectFiles::handleHelperUploads(active_project());
             } catch (Exception $e) {
                 flash_error(lang('error upload file'));
                 $this->redirectToUrl($object->getAttachFilesUrl());
             }
             // try
         }
         // if
         if (!is_array($attach_files) || !count($attach_files)) {
             flash_error(lang('no files to attach'));
             $this->redirectToUrl($object->getAttachFilesUrl());
         }
         // if
         try {
             DB::beginWork();
             $counter = 0;
             foreach ($attach_files as $attach_file) {
                 $object->attachFile($attach_file);
                 $counter++;
             }
             // foreach
             DB::commit();
             $object->onAttachFiles($attach_files);
             flash_success(lang('success attach files', $counter));
             $this->redirectToUrl($object->getObjectUrl());
         } catch (Exception $e) {
             DB::rollback();
             if (array_var($attach_data, 'what') == 'new_file' && count($attach_files)) {
                 foreach ($attach_files as $attach_file) {
                     $attach_file->delete();
                 }
                 // foreach
             }
             // if
             tpl_assign('error', $e);
         }
         // try
     }
     // if
 }
예제 #5
0
 /**
  * Add comment
  * 
  * Through this controller only logged users can post (no anonymous comments here)
  *
  * @param void
  * @return null
  */
 function add()
 {
     $this->setTemplate('add_comment');
     $object_id = get_id('object_id');
     $object_manager = array_var($_GET, 'object_manager');
     if (!is_valid_function_name($object_manager)) {
         flash_error(lang('invalid request'));
         $this->redirectToUrl(active_project()->getOverviewUrl());
     }
     // if
     $object = get_object_by_manager_and_id($object_id, $object_manager);
     if (!$object instanceof ProjectDataObject || !$object->canComment(logged_user())) {
         flash_error(lang('no access permissions'));
         $this->redirectToUrl(active_project()->getOverviewUrl());
     }
     // if
     $comment = new Comment();
     $comment_data = array_var($_POST, 'comment');
     tpl_assign('comment_form_object', $object);
     tpl_assign('comment', $comment);
     tpl_assign('comment_data', $comment_data);
     if (is_array($comment_data)) {
         try {
             try {
                 $attached_files = ProjectFiles::handleHelperUploads(active_project());
             } catch (Exception $e) {
                 $attached_files = null;
             }
             // try
             $comment->setFromAttributes($comment_data);
             $comment->setRelObjectId($object_id);
             $comment->setRelObjectManager($object_manager);
             if (!logged_user()->isMemberOfOwnerCompany()) {
                 $comment->setIsPrivate(false);
             }
             // if
             if ($object instanceof ProjectMessage || $object instanceof ProjectFile) {
                 if ($object->getIsPrivate()) {
                     $comment->setIsPrivate(true);
                 }
                 // if
             }
             // if
             DB::beginWork();
             $comment->save();
             if (is_array($attached_files)) {
                 foreach ($attached_files as $attached_file) {
                     $comment->attachFile($attached_file);
                 }
                 // foreach
             }
             // if
             ApplicationLogs::createLog($comment, active_project(), ApplicationLogs::ACTION_ADD);
             // Subscribe user to message (if $object is message)
             if ($object instanceof ProjectMessage) {
                 if (!$object->isSubscriber(logged_user())) {
                     $object->subscribeUser(logged_user());
                 }
                 // if
             }
             // if
             DB::commit();
             flash_success(lang('success add comment'));
             $redirect_to = $comment->getViewUrl();
             if (!is_valid_url($redirect_to)) {
                 $redirect_to = $object->getViewUrl();
             }
             // if
             $this->redirectToUrl($redirect_to);
         } catch (Exception $e) {
             DB::rollback();
             tpl_assign('error', $e);
         }
         // try
     }
     // if
 }
 /**
  * Link object to the object
  *
  * @param void
  * @return null
  */
 function link_to_object()
 {
     if (logged_user()->isGuest()) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     $manager_class = array_var($_GET, 'manager');
     $object_id = get_id('object_id');
     $object = get_object_by_manager_and_id($object_id, $manager_class);
     if (!$object instanceof ProjectDataObject) {
         flash_error(lang('no access permissions'));
         //$this->redirectToReferer(get_url('dashboard'));
         ajx_current("empty");
         return;
     }
     // if
     $already_linked_objects = $object->getLinkedObjects();
     $already_linked_objects_ids = null;
     if (is_array($already_linked_objects)) {
         $already_linked_objects_ids = array();
         foreach ($already_linked_objects as $already_linked_object) {
             $already_linked_objects_ids[] = $already_linked_object->getId();
         }
         // foreach
     }
     // if
     $link_data = array_var($_POST, 'link');
     if (!is_array($link_data)) {
         $link_data = array('what' => 'existing_object');
     }
     // if
     tpl_assign('link_to_object', $object);
     tpl_assign('link_data', $link_data);
     tpl_assign('already_linked_objects_ids', $already_linked_objects_ids);
     if (is_array(array_var($_POST, 'link'))) {
         if (array_var($link_data, 'what') == 'existing_object') {
             $link_data_info = explode('::', array_var($link_data, 'object_id'));
             echo $link_data_info[0] . '-' . $link_data_info[1];
             $object2 = get_object_by_manager_and_id($link_data_info[0], $link_data_info[1]);
             if (!$object2 instanceof ProjectDataObject) {
                 flash_error(lang('no object to link'));
                 $this->redirectToUrl($object->getLinkedObjectsUrl());
             }
             // if
             $linked_objects[] = $object2;
         } elseif (array_var($link_data, 'what') == 'new_object') {
             try {
                 $linked_objects = ProjectFiles::handleHelperUploads(active_project());
             } catch (Exception $e) {
                 flash_error(lang('error upload file'));
                 $this->redirectToUrl($object->getLinkedObjectsUrl());
             }
             // try
         }
         // if
         if (!is_array($linked_objects) || !count($linked_objects)) {
             flash_error(lang('no objects to link'));
             $this->redirectToUrl($object->getLinkedObjectsUrl());
         }
         // if
         try {
             DB::beginWork();
             $counter = 0;
             foreach ($linked_objects as $linked_object) {
                 $object->linkObject($linked_object);
                 if ($object instanceof ProjectDataObject) {
                     ApplicationLogs::createLog($object, $object->getWorkspaces(), ApplicationLogs::ACTION_LINK, false, null, true, get_class($linked_object->manager()) . ':' . $linked_object->getId());
                 }
                 if ($linked_object instanceof ProjectDataObject) {
                     ApplicationLogs::createLog($linked_object, $linked_object->getWorkspaces(), ApplicationLogs::ACTION_LINK, false, null, true, get_class($object->manager()) . ':' . $object->getId());
                 }
                 $counter++;
             }
             // foreach
             DB::commit();
             flash_success(lang('success link objects', $counter));
             $this->redirectToUrl($object->getObjectUrl());
         } catch (Exception $e) {
             DB::rollback();
             if (array_var($link_data, 'what') == 'new_object' && count($linked_objects)) {
                 foreach ($linked_objects as $linked_object) {
                     $linked_object->delete();
                 }
                 // foreach
             }
             // if
             flash_error($e->getMessage());
             ajx_current("empty");
         }
         // try
     }
     // if
 }
 /**
  * Add comment
  * 
  * Through this controller only logged users can post (no anonymous comments here)
  *
  * @param void
  * @return null
  */
 function add()
 {
     $this->setTemplate('add_comment');
     $object_id = get_id('object_id');
     $object_manager = array_var($_GET, 'object_manager');
     if (!is_valid_function_name($object_manager)) {
         flash_error(lang('invalid request'));
         $this->redirectToUrl(active_project()->getOverviewUrl());
     }
     // if
     $object = get_object_by_manager_and_id($object_id, $object_manager);
     if (!$object instanceof ProjectDataObject || !$object->canComment(logged_user())) {
         flash_error(lang('no access permissions'));
         $this->redirectToUrl(active_project()->getOverviewUrl());
     }
     // if
     $comment = new Comment();
     $comment_data = array_var($_POST, 'comment');
     if (!is_array($comment_data)) {
         $comment_data = array('text' => '', 'is_private' => config_option('default_private', false));
         // array
     }
     // if
     tpl_assign('comment_form_object', $object);
     tpl_assign('comment', $comment);
     tpl_assign('comment_data', $comment_data);
     if (is_array($comment_data)) {
         try {
             try {
                 $attached_files = ProjectFiles::handleHelperUploads(active_project());
             } catch (Exception $e) {
                 $attached_files = null;
             }
             // try
             $comment->setFromAttributes($comment_data);
             $comment->setRelObjectId($object_id);
             $comment->setRelObjectManager($object_manager);
             if (!logged_user()->isMemberOfOwnerCompany()) {
                 $comment->setIsPrivate(false);
             }
             // if
             if ($object instanceof ProjectMessage || $object instanceof ProjectFile) {
                 if ($object->getIsPrivate()) {
                     $comment->setIsPrivate(true);
                 }
                 // if
             }
             // if
             DB::beginWork();
             $comment->save();
             if (is_array($attached_files)) {
                 foreach ($attached_files as $attached_file) {
                     $comment->attachFile($attached_file);
                 }
                 // foreach
             }
             // if
             ApplicationLogs::createLog($comment, active_project(), ApplicationLogs::ACTION_ADD);
             // Subscribe user to object (if $object is subscribible)
             if ($object->isSubscribable()) {
                 if (!$object->isSubscriber(logged_user())) {
                     $object->subscribeUser(logged_user());
                 }
                 // if
             }
             // if
             DB::commit();
             // Try to send notification on comments other than Messages (messages already managed by subscription)
             if (!$comment->getObject() instanceof ProjectMessage) {
                 // Try to send notifications but don't break submission in case of an error
                 // define all the users to be notified - here all project users, from all companies.
                 // Restrictions if comment is private is taken into account in newOtherComment()
                 try {
                     $notify_people = array();
                     $project_companies = active_project()->getCompanies();
                     foreach ($project_companies as $project_company) {
                         $company_users = $project_company->getUsersOnProject(active_project());
                         if (is_array($company_users)) {
                             foreach ($company_users as $company_user) {
                                 if (array_var($comment_data, 'notify_company_' . $project_company->getId()) == 'checked' || array_var($comment_data, 'notify_user_' . $company_user->getId())) {
                                     $notify_people[] = $company_user;
                                 }
                                 // if
                             }
                             // if
                         }
                         // if
                     }
                     // if
                     Notifier::newOtherComment($comment, $notify_people);
                     // send notification email...
                 } catch (Exception $e) {
                     Logger::log("Error: Notification failed, " . $e->getMessage(), Logger::ERROR);
                 }
                 // try
             }
             // if
             flash_success(lang('success add comment'));
             $redirect_to = $comment->getViewUrl();
             if (!is_valid_url($redirect_to)) {
                 $redirect_to = $object->getObjectUrl();
             }
             // if
             $this->redirectToUrl($redirect_to);
         } catch (Exception $e) {
             DB::rollback();
             tpl_assign('error', $e);
         }
         // try
     }
     // if
 }
 /**
  * Add comment
  *
  * Through this controller only logged users can post (no anonymous comments here)
  *
  * @param void
  * @return null
  */
 function add()
 {
     $this->setTemplate('add_comment');
     $object_id = get_id('object_id');
     $object_manager = array_var($_GET, 'object_manager');
     if (!is_valid_function_name($object_manager)) {
         flash_error(lang('invalid request'));
         ajx_current("empty");
         return;
     }
     // if
     $object = get_object_by_manager_and_id($object_id, $object_manager);
     if (!$object instanceof ProjectDataObject || !$object->canComment(logged_user())) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     // if
     $comment = new Comment();
     $comment_data = array_var($_POST, 'comment');
     tpl_assign('comment_form_object', $object);
     tpl_assign('comment', $comment);
     tpl_assign('comment_data', $comment_data);
     if (is_array($comment_data)) {
         try {
             try {
                 $attached_files = ProjectFiles::handleHelperUploads(active_or_personal_project());
             } catch (Exception $e) {
                 $attached_files = null;
             }
             // try
             $comment->setFromAttributes($comment_data);
             $comment->setRelObjectId($object_id);
             $comment->setRelObjectManager($object_manager);
             //				if(!logged_user()->isMemberOfOwnerCompany()) {
             $comment->setIsPrivate(false);
             //				} // if
             DB::beginWork();
             $comment->save();
             if (is_array($attached_files)) {
                 foreach ($attached_files as $attached_file) {
                     $comment->attachFile($attached_file);
                 }
                 // foreach
             }
             // if
             // Subscribe user to object
             if (!$object->isSubscriber(logged_user())) {
                 $object->subscribeUser(logged_user());
             }
             // if
             if (strlen($comment->getText()) < 100) {
                 $comment_head = $comment->getText();
             } else {
                 $lastpos = strpos($comment->getText(), " ", 100);
                 if ($lastpos === false) {
                     $comment_head = $comment->getText();
                 } else {
                     $comment_head = substr($comment->getText(), 0, $lastpos) . "...";
                 }
             }
             $comment_head = html_to_text($comment_head);
             ApplicationLogs::createLog($object, $object->getWorkspaces(), ApplicationLogs::ACTION_COMMENT, false, null, true, $comment_head);
             DB::commit();
             flash_success(lang('success add comment'));
             ajx_current("reload");
         } catch (Exception $e) {
             DB::rollback();
             ajx_current("empty");
             flash_error($e->getMessage());
         }
         // try
     }
     // if
 }