/**
 * Select priority control
 * 
 * Params:
 * 
 * - Commong SELECT attributes
 * - Value - Selected priority
 *
 * @param array $params
 * @return string
 */
function smarty_function_select_priority_images($params, &$smarty)
{
    $priorities = array(PRIORITY_URGENT => lang('Urgent'), PRIORITY_HIGHEST => lang('Highest'), PRIORITY_HIGH => lang('High'), PRIORITY_NORMAL => lang('Normal'), PRIORITY_LOW => lang('Low'), PRIORITY_LOWEST => lang('Lowest'), PRIORITY_HOLD => lang('Hold'), '-99' => lang('Unknown'));
    $priorities_images = array(PRIORITY_URGENT => 'assets/images/icons/priority/urgent.png', PRIORITY_HIGHEST => 'assets/images/icons/priority/highest.gif', PRIORITY_HIGH => 'assets/images/icons/priority/high.gif', PRIORITY_NORMAL => 'assets/images/icons/priority/normal.gif', PRIORITY_LOW => 'assets/images/icons/priority/low.gif', PRIORITY_LOWEST => 'assets/images/icons/priority/lowest.gif', PRIORITY_HOLD => 'assets/images/icons/priority/hold.png', '-99' => 'assets/images/icons/priority/unknown.png');
    //BOF:mod
    $priority_not_set = false;
    if ($params['value'] == '0') {
        $link = mysql_connect(DB_HOST, DB_USER, DB_PASS);
        mysql_select_db(DB_NAME, $link);
        $query = "select isnull(priority) as priority_not_set from healingcrystals_project_objects where id='" . (int) $params['name'] . "'";
        $result = mysql_query($query, $link);
        $info = mysql_fetch_Assoc($result);
        if ($info['priority_not_set'] == '1') {
            $priority_not_set = true;
        }
        mysql_close($link);
    }
    if (!$priority_not_set) {
        //EOF:mod
        $params['sel-image'] = $priorities_images[$params['value']];
        $value = 0;
        if (isset($params['value'])) {
            $value = (int) $params['value'];
            //if($value > PRIORITY_HIGHEST || $value < PRIORITY_HOLD) {
            if ($value > PRIORITY_URGENT || $value < PRIORITY_HOLD) {
                $value = 0;
            }
            // if
        }
        // if
        //BOF:mod
    } else {
        $value = '-99';
        $params['sel-image'] = $priorities_images[$value];
    }
    unset($params['value']);
    //EOF:mod
    $params['id'] = $params['name'];
    $obj = new ProjectObject($params['id']);
    $params['name'] = strtolower($obj->getType()) . 'priorityimages_' . $params['name'];
    $params['class'] = 'imageList';
    $options = array();
    $options[] = option_tag('Priority', '-', array('data-skip' => 'true'));
    foreach ($priorities as $priority => $priority_text) {
        $option_attribites = $priority == $value ? array('selected' => true) : array();
        $option_attribites['data-icon'] = $priorities_images[$priority];
        $options[] = option_tag($priority_text, $priority, $option_attribites);
    }
    // if
    return select_box($options, $params);
}
/**
 * Handle on_project_object_moved event
 *
 * @param ProjectObject $object
 * @param Project $source
 * @param Project $destination
 * @return null
 */
function resources_handle_on_project_object_moved(&$object, &$source, &$destination)
{
    if ($object->can_have_subscribers) {
        $subscribers = $object->getSubscribers();
        if (is_foreachable($subscribers)) {
            foreach ($subscribers as $subscriber) {
                if (!$subscriber->isProjectMember($destination)) {
                    Subscriptions::unsubscribe($subscriber, $object);
                }
                // if
            }
            // foreach
        }
        // if
    }
    // if
    $object_ids = array();
    // Relations with milestones are carried out via milestone_id field
    if (instance_of($object, 'Milestone')) {
        db_execute('UPDATE ' . TABLE_PREFIX . 'project_objects SET milestone_id = 0 WHERE milestone_id = ?', $object->getId());
    }
    // if
    $rows = db_execute_all('SELECT id FROM ' . TABLE_PREFIX . 'project_objects WHERE type IN (?) AND parent_id = ?', array('task', 'comment', 'attachment', 'timerecord'), $object->getId());
    if (is_foreachable($rows)) {
        foreach ($rows as $row) {
            $object_ids[] = (int) $row['id'];
        }
        // foreach
        // Sub-objects (attachments for comments, time records for tasks, tasks for tickets)
        $rows = db_execute_all('SELECT id FROM ' . TABLE_PREFIX . 'project_objects WHERE parent_id IN (?)', $object_ids);
        if (is_foreachable($rows)) {
            foreach ($rows as $row) {
                $object_ids[] = (int) $row['id'];
            }
            // foreach
        }
        // if
        // Update objects and activity logs
        db_execute('UPDATE ' . TABLE_PREFIX . 'project_objects SET project_id = ? WHERE id IN (?)', $destination->getId(), $object_ids);
        db_execute('UPDATE ' . TABLE_PREFIX . 'activity_logs SET project_id = ? WHERE object_id IN (?)', $destination->getId(), $object_ids);
        // Clear cache
        cache_remove_by_pattern(TABLE_PREFIX . 'activity_logs_id_*');
        cache_remove_by_pattern(TABLE_PREFIX . 'project_objects_id_*');
    }
    // if
}
Example #3
0
/**
 * Attach files from some array to $to object
 * 
 * - $from keys : - path
 *                - filename
 *                - type
 *
 * @param array $from
 * @param ProjectObject $to
 */
function attach_from_array(&$from, &$to)
{
    $attached = 0;
    if (is_foreachable($from)) {
        foreach ($from as $file) {
            $attach = $to->attachFile($file['path'], $file['filename'], $file['type']);
            if (is_error($attach) || !$attach) {
                $to->clearPendingFiles();
                return $attach;
            } else {
                $attached++;
            }
            // if
        }
        // foreach
    }
    // if
    return $attached;
}
 /**
  * Render popup content
  *
  * @param void
  * @return null
  */
 function _render_popup_content()
 {
     if (!instance_of($this->active_object, 'ProjectObject')) {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     // if
     if (TimeRecord::canAdd($this->logged_user, $this->active_project)) {
         $add_record_url = timetracking_module_add_record_url($this->active_project, array('for' => $this->active_object->getId(), 'for_popup_dialog' => 1));
     } else {
         $add_record_url = false;
     }
     // if
     $object_time = TimeRecords::sumObjectTime($this->active_object);
     $tasks_time = $this->active_object->can_have_tasks ? TimeRecords::sumTasksTime($this->active_object) : 0;
     $this->smarty->assign(array('selected_user' => $this->logged_user, 'selected_date' => new DateValue(time() + get_user_gmt_offset($this->logged_user)), 'selected_billable_status' => BILLABLE_STATUS_BILLABLE, 'object_time' => float_format($object_time, 2), 'tasks_time' => float_format($tasks_time, 2), 'total_time' => float_format($object_time + $tasks_time, 2), 'add_url' => $add_record_url));
     $this->smarty->display(get_template_path('_popup', null, TIMETRACKING_MODULE));
     die;
 }
 function convert_object_to_page()
 {
     $process_mode = $_GET['process'];
     $message = '';
     if (empty($process_mode)) {
         switch ($this->active_object->getType()) {
             case 'Milestone':
                 $message = 'This action will convert the Project: "' . $this->active_object->getName() . '" to Page.';
                 break;
             case 'Ticket':
                 $message = 'This action will convert the Ticket: "' . $this->active_object->getName() . '" to Page.';
                 break;
         }
     } else {
         $error = '';
         $page_id = $this->active_object->convertToPage($this->logged_user, $error);
         if (!empty($page_id)) {
             $this->redirectToUrl(assemble_url('project_page', array('project_id' => $this->active_project->getId(), 'page_id' => $page_id)));
         }
     }
     $this->smarty->assign(array('message' => $message, 'redirect_url' => assemble_url('project_object_convert_to_page', array('project_id' => $this->active_object->getProjectId(), 'object_id' => $this->active_object->getId(), 'process' => '1'))));
 }
 /**
  * Remove comment from database
  *
  * @param void
  * @return boolean
  */
 function delete()
 {
     $delete = parent::delete();
     if ($delete && !is_error($delete)) {
         $parent = $this->getParent();
         event_trigger('on_comment_deleted', array(&$this, &$parent));
     }
     // if
     return $delete;
 }
 function move()
 {
     $new_parent_id = $this->request->post('new_parent_id');
     $new_parent_type = $this->request->post('new_parent_type');
     $new_parent_url = '';
     $move_mode = false;
     if (!empty($new_parent_id) && !empty($new_parent_type)) {
         $move_mode = true;
         $parent_obj = $sql_part = null;
         switch ($new_parent_type) {
             case 'milestone':
                 $parent_obj = new MileStone($new_parent_id);
                 break;
             case 'ticket':
                 $parent_obj = new Ticket($new_parent_id);
                 break;
             case 'page':
                 $parent_obj = new Page($new_parent_id);
                 break;
         }
         if ($parent_obj) {
             $body = $this->active_task->getBody();
             $doc = new DOMDocument();
             if ($doc->loadHTML($body)) {
                 $anc_tags = $doc->getElementsByTagName('a');
                 $new_parent_url = '';
                 foreach ($anc_tags as $anc) {
                     if ($anc->nodeValue == 'View Task in Full') {
                         $href = $anc->getAttribute('href');
                         $fragment = substr($href, strpos($href, '#'));
                         $anc->setAttribute('href', $parent_obj->getViewUrl() . $fragment);
                         break;
                     }
                 }
                 if (!empty($fragment)) {
                     $body_tag = $doc->getElementsByTagName('body');
                     $body = $doc->saveXML($body_tag->item(0)->firstChild);
                     $comment_id = str_replace('#comment', '', $fragment);
                 }
             }
             $link = mysql_connect(DB_HOST, DB_USER, DB_PASS);
             mysql_select_db(DB_NAME);
             $query = "update \n\t\t\t\t\t\t\thealingcrystals_project_objects \n\t\t\t\t\t\t  set \n\t\t\t\t\t\t\tproject_id='" . $parent_obj->getProjectId() . "', \n\t\t\t\t\t\t\tmilestone_id='" . $parent_obj->getMilestoneId() . "', \n\t\t\t\t\t\t\tparent_id='" . $parent_obj->getId() . "', \n\t\t\t\t\t\t\tparent_type='" . $parent_obj->getType() . "', \n\t\t\t\t\t\t\tbody = '" . mysql_real_escape_string($body) . "' \n\t\t\t\t\t\t  where\tid='" . $this->active_task->getId() . "'";
             mysql_query($query, $link);
             if (!empty($comment_id)) {
                 $comment_query = "update \n\t\t\t\t\t\t\thealingcrystals_project_objects \n\t\t\t\t\t\t  set \n\t\t\t\t\t\t\tproject_id='" . $parent_obj->getProjectId() . "', \n\t\t\t\t\t\t\tmilestone_id='" . $parent_obj->getMilestoneId() . "', \n\t\t\t\t\t\t\tparent_id='" . $parent_obj->getId() . "', \n\t\t\t\t\t\t\tparent_type='" . $parent_obj->getType() . "', \n\t\t\t\t\t\t\tposition=null\n\t\t\t\t\t\t  where\tid='" . $comment_id . "'";
                 mysql_query($comment_query, $link);
             }
             mysql_close($link);
             $new_parent_url = $parent_obj->getViewUrl() . '#task' . $this->active_task->getId();
             $cache_id = TABLE_PREFIX . 'project_objects_id_' . $this->active_task->getId();
             $cache_obj = cache_get($cache_id);
             if ($cache_obj) {
                 cache_remove($cache_id);
             }
         }
     } else {
         $listing = array();
         switch ($this->active_task_parent->getType()) {
             case 'Milestone':
                 //$listing = Milestones::findByProject($this->active_project, $this->logged_user);
                 $listing = Milestones::findActiveByProject_custom($this->active_project);
                 break;
             case 'Ticket':
                 $listing = Tickets::findOpenByProjectByNameSort($this->active_project, STATE_VISIBLE, $this->logged_user->getVisibility());
                 break;
             case 'Page':
                 $categories = Categories::findByModuleSection($this->active_project, 'pages', 'pages');
                 $listing = Pages::findByCategories($categories, STATE_VISIBLE, $this->logged_user->getVisibility());
                 /*foreach($categories as $category){
                 			$listing = array_merge($listing, Pages::findByCategory($category, STATE_VISIBLE, $this->logged_user->getVisibility()));
                 		}*/
                 break;
         }
         $this->smarty->assign(array('teams' => Projects::findNamesByUser($this->logged_user), 'listing' => $listing, 'task_parent_id' => $this->active_task_parent->getId()));
     }
     $this->smarty->assign('new_parent_url', $new_parent_url);
     $this->smarty->assign('move_mode', $move_mode);
 }
 /**
  * Save into database
  * 
  * @return boolean
  */
 function save()
 {
     if ($this->isNew()) {
         $this->setTicketId(Tickets::findNextTicketIdByProject($this->getProjectId()));
     }
     // if
     $changes = null;
     if ($this->isLoaded()) {
         $log_fields = array('project_id', 'milestone_id', 'parent_id', 'name', 'body', 'priority', 'due_on', 'completed_on');
         $changes = new TicketChange();
         $changes->setTicketId($this->getId());
         $changes->setVersion($this->getVersion());
         $changes->setCreatedOn(DateTimeValue::now());
         $changes->setCreatedBy(get_logged_user());
         if ($this->new_assignees !== false) {
             list($old_assignees, $old_owner_id) = $this->getAssignmentData();
             if (is_array($this->new_assignees) && isset($this->new_assignees[0]) && isset($this->new_assignees[1])) {
                 $new_assignees = $this->new_assignees[0];
                 $new_owner_id = $this->new_assignees[1];
             } else {
                 $new_assignees = array();
                 $new_owner_id = 0;
             }
             // if
             if ($new_owner_id != $old_owner_id) {
                 $changes->addChange('owner', $old_owner_id, $new_owner_id);
             }
             // if
             sort($new_assignees);
             sort($old_assignees);
             if ($new_assignees != $old_assignees) {
                 $changes->addChange('assignees', $old_assignees, $new_assignees);
             }
             // if
         }
         // if
         foreach ($this->modified_fields as $field) {
             if (!in_array($field, $log_fields)) {
                 continue;
             }
             // if
             $old_value = array_var($this->old_values, $field);
             $new_value = array_var($this->values, $field);
             if ($old_value != $new_value) {
                 $changes->addChange($field, $old_value, $new_value);
             }
             // if
         }
         // foreach
     }
     // if
     $save = parent::save();
     if ($save && !is_error($save)) {
         if (instance_of($changes, 'TicketChange') && count($changes->changes)) {
             $this->changes = false;
             $changes->save();
         }
         // if
     }
     // if
     return $save;
 }
 /**
  * Delete assignmnets by project object
  *
  * @param ProjectObject $object
  * @return boolean
  */
 function deleteByObject($object)
 {
     cache_remove('object_assignments_' . $object->getId());
     cache_remove('object_assignments_' . $object->getId() . '_rendered');
     return Assignments::delete(array('object_id = ?', $object->getId()));
 }
Example #10
0
 function link_unvisited($comment_id)
 {
     //BOF:mod 20111019 #448
     $temp_obj = new ProjectObject($comment_id);
     $object_type = $temp_obj->getType();
     //EOF:mod 20111019
     $is_unvisited = true;
     $link = mysql_connect(DB_HOST, DB_USER, DB_PASS);
     mysql_select_db(DB_NAME, $link);
     //BOF:mod 20111019 #448
     if ($object_type == 'Comment') {
         //EOF:mod 20111019 #448
         $query = "select link_is_visited from healingcrystals_assignments_action_request where user_id='" . $this->getId() . "' and comment_id='" . (int) $comment_id . "'";
         //BOF:mod 20111019 #448
     } else {
         $query = "select link_is_visited from healingcrystals_assignments_flag_fyi_actionrequest where user_id='" . $this->getId() . "' and object_id='" . (int) $comment_id . "'";
     }
     //EOF:mod 20111019 #448
     $result = mysql_query($query);
     if (mysql_num_rows($result)) {
         $info = mysql_fetch_assoc($result);
         if ($info['link_is_visited']) {
             $is_unvisited = false;
         }
     }
     mysql_close($link);
     return $is_unvisited;
 }
 /**
  * Clear reminders by object
  *
  * @param ProjectObject $object
  * @return boolean
  */
 function deleteByObject($object)
 {
     return Reminders::delete(array('object_id = ?', $object->getId()));
 }
 /**
  * DElete by object
  *
  * @param ProjectObject $object
  * @return boolean
  */
 function deleteByObject($object)
 {
     return Attachments::delete(array('parent_id = ? AND parent_type = ?', $object->getId(), get_class($object)));
 }
 /**
  * Returns true if $object is viewed by $user
  *
  * @param ProjectObject $object
  * @param User $user
  * @return boolan
  */
 function isViewed($object, $user)
 {
     return (bool) array_var(db_execute_one("SELECT COUNT(*) AS 'row_count' FROM " . TABLE_PREFIX . 'project_object_views WHERE object_id = ? AND created_by_id = ?', $object->getId(), $user->getId()), 'row_count');
 }
Example #14
0
 /**
  * Validate before save
  *
  * @param ValidationErrors $errors
  * @return null
  */
 function validate(&$errors)
 {
     if (!$this->validatePresenceOf('body', 3)) {
         $errors->addError(lang('Task text is required. Min length is 3 letters'), 'body');
     }
     // if
     parent::validate($errors, true);
 }
 /**
  * Toggles object completed state
  * 
  */
 function toggle_completed()
 {
     $object_id = (int) $this->request->get('object_id');
     if ($object_id) {
         $object = ProjectObjects::findById($object_id);
     } else {
         $object = new ProjectObject();
     }
     // if
     if ($object->isNew()) {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     // if
     if ($object->isCompleted()) {
         $object->open($this->logged_user);
     } else {
         $object->complete($this->logged_user);
     }
     $this->redirectToUrl(mobile_access_module_get_view_url($object));
 }
 /**
  * Delete subscriptions by parent
  *
  * @param ProjectObject $parent
  * @return boolean
  */
 function deleteByParent($parent)
 {
     cache_remove_by_pattern('user_subscriptions_*');
     return Subscriptions::delete(array('parent_id = ?', $parent->getId()));
 }
 /**
  * Drop records by object
  *
  * @param ProjectObject $object
  * @return boolean
  */
 function deleteByObject($object)
 {
     return db_execute('DELETE FROM ' . TABLE_PREFIX . 'starred_objects WHERE object_id = ?', $object->getId());
 }
 /**
  * Return portal repository view URL
  *
  * @param Portal $portal
  * @param integer $page
  * @return string
  */
 function getPortalViewUrl($portal, $page = null)
 {
     $params = $page === nul ? null : array('page' => $page);
     return parent::getPortalViewUrl($portal, $page);
 }
 function render_comments()
 {
     $response = '<table width="100%" style="border:5px solid #dddddd;">';
     $user_id = $this->request->get('user_id');
     if (empty($user_id)) {
         $user_id = $this->request->post('user_id');
         if (empty($user_id)) {
             $user_id = $this->logged_user->getId();
         }
     }
     $action_type = $_GET['action_type'];
     $parent_id = $_GET['parent_id'];
     $temp_obj = new ProjectObject($parent_id);
     $parenttype = $temp_obj->getType();
     $parentobj = new $parenttype($parent_id);
     $projectobj = new Project($parentobj->getProjectId());
     $milestone_id = $parentobj->getMilestoneId();
     if (!empty($milestone_id)) {
         $milestoneobj = new Milestone($milestone_id);
     }
     $assigneesstring = '';
     list($assignees, $owner_id) = $parentobj->getAssignmentData();
     foreach ($assignees as $assignee) {
         $assigneeobj = new User($assignee);
         $assigneesstring .= '<a target="_blank" href="' . $assigneeobj->getViewUrl() . '">' . $assigneeobj->getName() . '</a>, ';
         unset($assigneeobj);
     }
     if (!empty($assigneesstring)) {
         $assigneesstring = substr($assigneesstring, 0, -2);
     }
     $dueon = date('F d, Y', strtotime($parentobj->getDueOn()));
     if ($dueon == 'January 01, 1970') {
         $dueon = '--';
     }
     if ($milestoneobj) {
         $priority = $milestoneobj->getPriority();
         if (!empty($priority) || $priority == '0') {
             $priority = $milestoneobj->getFormattedPriority();
         } else {
             $priority = '--';
         }
     } else {
         $priority = '--';
     }
     $response .= '
             <tr><td colspan="2" style="height:20px;">&nbsp;</td></tr>
                 <tr>
                     <td style="width:25%;" valign="top">' . $parenttype . '</td>
                     <td valign="top">
                         <a target="_blank" href="' . $parentobj->getViewUrl() . '"><span class="homepageobject">' . $parentobj->getName() . '</span></a>
                     </td>
                 </tr>
                 <tr>
                     <td valign="top">Team &raquo; Project</td>
                     <td valign="top">
                         <a target="_blank" href="' . $projectobj->getOverviewUrl() . '"><span class="homepageobject">' . $projectobj->getName() . '</span></a> &raquo; ' . ($milestoneobj ? '<a target="_blank" href="' . $milestoneobj->getViewUrl() . '"><span class="homepageobject">' . $milestoneobj->getName() . '</a></span>' : '--') . '</td>
                 </tr>
                 <tr>
                     <td vlaign="top">Project Priority</td>
                     <td valign="top">' . $priority . '</td>
                 </tr>
                 <tr>
                     <td valign="top">Due on</td>
                     <td valign="top">' . $dueon . '</td>
                 </tr>
                 <tr>
                     <td valign="top">Assignees</td>
                     <td valign="top">' . $assigneesstring . '</td>
                 </tr>
                 <tr><td colspan="2" style="height:20px;">&nbsp;</td></tr>';
     $link = mysql_connect(DB_HOST, DB_USER, DB_PASS);
     mysql_select_db(DB_NAME, $link);
     if ($action_type == 'actionrequest') {
         $query = "(select b.id, d.id as parent_ref , a.date_added as date_value, e.priority as prio, c.name as project_name\n                     from healingcrystals_assignments_action_request a\n                     inner join healingcrystals_project_objects b on a.comment_id=b.id\n                     inner join healingcrystals_project_objects d on b.parent_id=d.id\n                     left outer join healingcrystals_project_objects e on d.milestone_id=e.id\n                     inner join healingcrystals_projects c on b.project_id=c.id\n                     where d.id='" . $parent_id . "' and b.state='" . STATE_VISIBLE . "' and a.user_id='" . $user_id . "' and a.is_action_request='1'\n                     and d.state='" . STATE_VISIBLE . "'  )\n                     union\n                     (select '' as id, a.object_id as parent_ref, b.created_on as date_value, e.priority as prio, c.name as project_name\n                     from healingcrystals_assignments_flag_fyi_actionrequest a\n                     inner join healingcrystals_project_objects b on a.object_id=b.id\n                     left outer join healingcrystals_project_objects e on b.milestone_id=e.id\n                     inner join healingcrystals_projects c on b.project_id=c.id\n                     where a.user_id='" . $user_id . "' and a.object_id='" . $parent_id . "' and flag_actionrequest='1' and b.state='" . STATE_VISIBLE . "'\n                      )\n                     order by prio desc, project_name, date_value desc";
     } elseif ($action_type == 'fyi') {
         $query = "(select b.id, d.id as parent_ref , a.date_added as date_value, e.priority as prio, c.name as project_name\n                     from healingcrystals_assignments_action_request a\n                     inner join healingcrystals_project_objects b on a.comment_id=b.id\n                     inner join healingcrystals_project_objects d on b.parent_id=d.id\n                     left outer join healingcrystals_project_objects e on d.milestone_id=e.id\n                     inner join healingcrystals_projects c on b.project_id=c.id\n                     where d.id='" . $parent_id . "' and b.state='" . STATE_VISIBLE . "' and a.user_id='" . $user_id . "' and a.is_fyi='1'\n                     and d.state='" . STATE_VISIBLE . "' )\n                     union\n                     (select '' as id, a.object_id as parent_ref, b.created_on as date_value, e.priority as prio, c.name as project_name\n                     from healingcrystals_assignments_flag_fyi_actionrequest a\n                     inner join healingcrystals_project_objects b on a.object_id=b.id\n                     left outer join healingcrystals_project_objects e on b.milestone_id=e.id\n                     inner join healingcrystals_projects c on b.project_id=c.id\n                     where a.user_id='" . $user_id . "' and a.object_id='" . $parent_id . "' and flag_fyi='1' and b.state='" . STATE_VISIBLE . "'\n                      )\n                     order by prio desc, project_name, date_value desc";
     }
     $result = mysql_query($query);
     $count = 0;
     while ($entry = mysql_fetch_assoc($result)) {
         $count++;
         if (!empty($entry['id'])) {
             $temp_obj = new Comment($entry['id']);
             $created_by_id = $temp_obj->getCreatedById();
             $created_by_user = new User($created_by_id);
             $created_on = strtotime($temp_obj->getCreatedOn());
             $created_on = date('m-d-y', $created_on);
             $temp = $temp_obj->getFormattedBody(true, true);
             $comment_body = $temp;
             $response .= '
                     <tr>
                         <td valign="top" style="vertical-align:top;">
                             Comment by<br/>' . (!empty($created_by_id) ? '<a target="_blank" href="' . $created_by_user->getViewUrl() . '">' . $created_by_user->getName() . '</a>' : $temp_obj->getCreatedByName()) . '<br/><br/><br/>
                             <a target="_blank" href="' . $temp_obj->getViewUrl() . '">[view comment]</a><br/>&nbsp;&nbsp;&nbsp;' . $created_on . '<br/><br/><br/>' . ($action_type == 'actionrequest' ? '<a class="mark_as_complete" count="' . $count . '" href="' . assemble_url('project_comment_action_request_completed', array('project_id' => $temp_obj->getProjectId(), 'comment_id' => $temp_obj->getId())) . '">Mark Action Request Complete</a>' : '') . ($action_type == 'fyi' ? '<a class="mark_as_read" count="' . $count . '" href="' . assemble_url('project_comment_fyi_read', array('project_id' => $temp_obj->getProjectId(), 'comment_id' => $temp_obj->getId())) . '">Mark this Notification<br/>as Read</a>' : '') . '</td>
                         <td valign="top" style="vertical-align:top;">
                             <div style="width:600px;overflow:auto;">' . $comment_body . '</div>' . ($show_read_link ? '<a target="_blank" href="' . $temp_obj->getViewUrl() . '">Click here to read the rest of this Comment</a>' : '') . '</td>
                     </tr>
                     <tr><td colspan="2" style="height:20px;">&nbsp;</td></tr>';
         } else {
             $response .= '
                     <tr>
                        <td valign="top" style="vertical-align:top;">
                             Created by<br/>' . (!empty($created_by_id) ? '<a target="_blank" href="' . $created_by_user->getViewUrl() . '">' . $created_by_user->getName() . '</a>' : $parentobj->getCreatedByName()) . '<br/><br/><br/>
                             <a target="_blank" href="' . $parentobj->getViewUrl() . '">[view object]</a><br/>&nbsp;&nbsp;&nbsp;' . $created_on . '<br/><br/><br/>' . ($action_type == 'action_request' ? '<a class="mark_as_complete" count="' . $count . '" href="' . assemble_url('project_object_action_request_completed', array('project_id' => $parentobj->getProjectId())) . '&object_id=' . $parentobj->getId() . '&project_id=' . $parentobj->getProjectId() . '">Mark Action Request Complete</a>' : '') . ($action_type == 'fyi' ? '<a class="mark_as_read" count="' . $count . '" href="' . assemble_url('project_object_fyi_read', array('project_id' => $parentobj->getProjectId())) . '&object_id=' . $parentobj->getId() . '&project_id=' . $parentobj->getProjectId() . '">Mark this Notification<br/>as Read</a>' : '') . '</td>
                         <td valign="top" style="vertical-align:top;">
                             <div style="width:600px;overflow:auto;">' . $parentobj->getFormattedBody(true, true) . '</div>
                         </td>
                     </tr>
                     <tr><td colspan="2" style="height:20px;">&nbsp;</td></tr>';
         }
     }
     mysql_close($link);
     $response .= '</table>';
     $this->smarty->assign('response', $response);
 }
 /**
  * Get CreatedBy information
  *
  * @param Repository $repository
  * @return User
  */
 function getCreatedBy($repository = null)
 {
     if (is_null($repository)) {
         $repository = Repositories::findById($this->getParentId());
         $repository->mapped_users = SourceUsers::findByRepository($repository);
     }
     // if
     if (isset($repository->mapped_users[$this->getCreatedByName()]) && instance_of($repository->mapped_users[$this->getCreatedByName()], 'SourceUser')) {
         $source_user = $repository->mapped_users[$this->getCreatedByName()];
         if (instance_of($source_user->system_user, 'User')) {
             return $source_user->system_user;
         }
         // if
     }
     // if
     return parent::getCreatedBy();
 }
 /**
  * Return number of hours tracked for tasks attached to $object
  *
  * @param ProjectObject $object
  * @return float
  */
 function sumTasksTime($object)
 {
     $rows = db_execute_all('SELECT id FROM ' . TABLE_PREFIX . 'project_objects WHERE parent_id = ? AND type = ?', $object->getId(), 'Task');
     if (is_foreachable($rows)) {
         $task_ids = array();
         foreach ($rows as $row) {
             $task_ids[] = (int) $row['id'];
         }
         // foreach
         return (double) array_var(db_execute_one("SELECT SUM(float_field_1) AS 'time_sum' FROM " . TABLE_PREFIX . "project_objects WHERE parent_id IN (?) AND state >= ?", $task_ids, STATE_VISIBLE), 'time_sum');
     } else {
         return 0;
     }
     // if
 }
 /**
  * Update field properties for child objects by parent
  * 
  * $properties is an array where key is setter name and value is new value
  *
  * @param ProjectObject $parent
  * @param array $properties
  * @param array $types
  * @return boolean
  */
 function updatePropertiesByParent($parent, $properties, $types)
 {
     if (is_foreachable($properties) && is_foreachable($types)) {
         $objects = ProjectObjects::findBySQL('SELECT * FROM ' . TABLE_PREFIX . 'project_objects WHERE parent_id = ? AND type IN (?)', array($parent->getId(), $types));
         if (is_foreachable($objects)) {
             db_begin_work();
             foreach ($objects as $object) {
                 foreach ($properties as $setter => $value) {
                     $object->{$setter}($value);
                 }
                 // if
                 $object->save();
             }
             // foreach
             db_commit();
         }
         // if
     }
     // if
     return true;
 }
 function search($search_for, $type, $user, $page = 1, $per_page = 30, $search_object_type = '', $search_under_project_id = '', $datesort = '')
 {
     //EOF:mod 20120711
     $page = (int) $page;
     $per_page = (int) $per_page;
     $search_index_table = TABLE_PREFIX . 'search_index';
     $offset = ($page - 1) * $per_page;
     // Search in projects
     if ($type == 'ProjectObject') {
         $type_filter = ProjectUsers::getVisibleTypesFilter($user, array(PROJECT_STATUS_ACTIVE, PROJECT_STATUS_PAUSED, PROJECT_STATUS_COMPLETED, PROJECT_STATUS_CANCELED));
         if (empty($type_filter)) {
             return array(null, new Pager(1, 0, $per_page));
         }
         // if
         if (strlen($search_for) <= 2) {
             return array(null, new Pager(1, 0, $per_page));
         }
         //BOF:mod 20111102
         // $search_for = str_replace(' ', '% %', $search_for);
         //EOF:mod 20111102
         $project_objects_table = TABLE_PREFIX . 'project_objects';
         //$total_items = (integer) array_var(db_execute_one("SELECT COUNT($project_objects_table.id) AS 'row_count' FROM $project_objects_table, $search_index_table WHERE $type_filter AND MATCH ($search_index_table.content) AGAINST (? IN BOOLEAN MODE) AND $project_objects_table.id = $search_index_table.object_id AND $search_index_table.type = ? AND state >= ? AND visibility >= ?", $search_for, $type, STATE_VISIBLE, $user->getVisibility()), 'row_count');
         /*if (empty($search_object_type)){
           	$total_items = (integer) array_var(db_execute_one("SELECT COUNT($project_objects_table.id) AS 'row_count' FROM $project_objects_table, $search_index_table WHERE $type_filter AND MATCH ($search_index_table.content) AGAINST (? IN BOOLEAN MODE) AND $project_objects_table.id = $search_index_table.object_id AND $search_index_table.type = ? AND state >= ? AND visibility >= ?", $search_for, $type, STATE_VISIBLE, $user->getVisibility()), 'row_count');
           } else {
           	$total_items = (integer) array_var(db_execute_one("SELECT COUNT($project_objects_table.id) AS 'row_count' FROM $project_objects_table, $search_index_table WHERE $type_filter AND MATCH ($search_index_table.content) AGAINST (? IN BOOLEAN MODE) AND $project_objects_table.id = $search_index_table.object_id AND $search_index_table.type = ? AND state >= ? AND visibility >= ? AND $project_objects_table.type = ?", $search_for, $type, STATE_VISIBLE, $user->getVisibility(), $search_object_type), 'row_count');
           }*/
         $complete_str = '';
         if ($_GET['complete'] != '1') {
             $complete_str = " and healingcrystals_project_objects.completed_on is null and (healingcrystals_project_objects.completed_by_id is null or healingcrystals_project_objects.completed_by_id='0') and healingcrystals_project_objects.boolean_field_1 is null ";
         }
         $link = mysql_connect(DB_HOST, DB_USER, DB_PASS);
         mysql_select_db(DB_NAME);
         $query_main = "(select healingcrystals_sort_order_for_search.sort_order, if(healingcrystals_project_objects.completed_on is null, '0', '1'), '0' as new_order, healingcrystals_project_objects.* \n\t\t  \t\t from healingcrystals_project_objects " . (!empty($search_under_project_id) ? " inner join healingcrystals_projects on (healingcrystals_project_objects.project_id=healingcrystals_projects.id and  healingcrystals_project_objects.project_id='" . (int) $search_under_project_id . "') " : " ") . " inner join healingcrystals_search_index on healingcrystals_project_objects.id=healingcrystals_search_index.object_id \n\t\t  \t\t left join healingcrystals_sort_order_for_search on healingcrystals_sort_order_for_search.type=healingcrystals_project_objects.type \n\t\t\t\t where " . $type_filter . $complete_str . " \n\t\t\t\t and (healingcrystals_project_objects.name is not null) \n\t\t\t\t and (healingcrystals_project_objects.name like '%" . addslashes($search_for) . "%') \n\t\t\t\t and healingcrystals_search_index.type='" . $type . "' \n\t\t\t\t and healingcrystals_project_objects.state='" . STATE_VISIBLE . "' " . (empty($search_object_type) ? "" : " and healingcrystals_project_objects.type='" . $search_object_type . "' ") . " )\n\t\t\t\t UNION \n\t\t\t\t (select healingcrystals_sort_order_for_search.sort_order, if(healingcrystals_project_objects.completed_on is null, '0', '1'), '0' as new_order, healingcrystals_project_objects.* \n\t\t  \t\t from healingcrystals_project_objects " . (!empty($search_under_project_id) ? " inner join healingcrystals_projects on (healingcrystals_project_objects.project_id=healingcrystals_projects.id and  healingcrystals_project_objects.project_id='" . (int) $search_under_project_id . "') " : " ") . " inner join healingcrystals_search_index on healingcrystals_project_objects.id=healingcrystals_search_index.object_id \n\t\t  \t\t left join healingcrystals_sort_order_for_search on healingcrystals_sort_order_for_search.type=healingcrystals_project_objects.type \n\t\t\t\t where " . $type_filter . $complete_str . " \n\t\t\t\t and (healingcrystals_project_objects.body like '%" . addslashes($search_for) . "%') and \n\t\t\t\t (healingcrystals_project_objects.name is null or healingcrystals_project_objects.name='') \n\t\t\t\t and healingcrystals_search_index.type='" . $type . "' \n\t\t\t\t and healingcrystals_project_objects.state='" . STATE_VISIBLE . "' " . (empty($search_object_type) ? "" : " and healingcrystals_project_objects.type='" . $search_object_type . "' ") . " ) ";
         $count_query_main = "(select * \n\t\t  \t\t from healingcrystals_project_objects " . (!empty($search_under_project_id) ? " inner join healingcrystals_projects on (healingcrystals_project_objects.project_id=healingcrystals_projects.id and  healingcrystals_project_objects.project_id='" . (int) $search_under_project_id . "') " : " ") . " inner join healingcrystals_search_index on healingcrystals_project_objects.id=healingcrystals_search_index.object_id \n\t\t  \t\t left join healingcrystals_sort_order_for_search on healingcrystals_sort_order_for_search.type=healingcrystals_project_objects.type \n\t\t\t\t where " . $type_filter . $complete_str . " and (healingcrystals_project_objects.name is not null) \n\t\t\t\t and (healingcrystals_project_objects.name like '%" . addslashes($search_for) . "%') \n\t\t\t\t and healingcrystals_search_index.type='" . $type . "' \n\t\t\t\t and healingcrystals_project_objects.state='" . STATE_VISIBLE . "' " . (empty($search_object_type) ? "" : " and healingcrystals_project_objects.type='" . $search_object_type . "' ") . " )\n\t\t\t\t UNION \n\t\t\t\t (select * from healingcrystals_project_objects " . (!empty($search_under_project_id) ? " inner join healingcrystals_projects on (healingcrystals_project_objects.project_id=healingcrystals_projects.id and  healingcrystals_project_objects.project_id='" . (int) $search_under_project_id . "') " : " ") . " inner join healingcrystals_search_index on healingcrystals_project_objects.id=healingcrystals_search_index.object_id \n\t\t  \t\t left join healingcrystals_sort_order_for_search on healingcrystals_sort_order_for_search.type=healingcrystals_project_objects.type \n\t\t\t\t where " . $type_filter . $complete_str . " \n\t\t\t\t and (healingcrystals_project_objects.body like '%" . addslashes($search_for) . "%')  and \n\t\t\t\t (healingcrystals_project_objects.name is null or healingcrystals_project_objects.name='') \n\t\t\t\t and healingcrystals_search_index.type='" . $type . "' \n\t\t\t\t and healingcrystals_project_objects.state='" . STATE_VISIBLE . "' " . (empty($search_object_type) ? "" : " and healingcrystals_project_objects.type='" . $search_object_type . "' ") . " ) ";
         //BOF-20120216
         if (strpos($search_for, ' ') !== false) {
             $all_parts_in_name_string = '';
             $all_parts_in_body_string = '';
             $few_parts_in_name_string = '';
             $string_parts = explode(' ', $search_for);
             $query_parts_name = array();
             $query_parts_description = array();
             foreach ($string_parts as $part) {
                 $query_parts_name[] = "healingcrystals_project_objects.name like '%" . addslashes($part) . "%'";
                 $query_parts_description[] = "healingcrystals_project_objects.body like '%" . addslashes($part) . "%'";
             }
             $all_parts_in_name_string = implode(" and ", $query_parts_name);
             $all_parts_in_body_string = implode(" and ", $query_parts_description);
             $few_parts_in_name_string = implode(" or ", $query_parts_name);
             $few_parts_in_body_string = implode(" or ", $query_parts_description);
             $query_main = "(select distinct(healingcrystals_project_objects.id), healingcrystals_sort_order_for_search.sort_order, if(healingcrystals_project_objects.completed_on is null, '0', '1'), if(healingcrystals_project_objects.name like '%" . addslashes($search_for) . "%','1', if(" . $all_parts_in_name_string . ",'3',if(" . $few_parts_in_name_string . ",'5','99'))) as new_order, healingcrystals_project_objects.* \n\t\t  \t\t from healingcrystals_project_objects " . (!empty($search_under_project_id) ? " inner join healingcrystals_projects on (healingcrystals_project_objects.project_id=healingcrystals_projects.id and  healingcrystals_project_objects.project_id='" . (int) $search_under_project_id . "') " : " ") . " inner join healingcrystals_search_index on healingcrystals_project_objects.id=healingcrystals_search_index.object_id \n\t\t  \t\t left join healingcrystals_sort_order_for_search on healingcrystals_sort_order_for_search.type=healingcrystals_project_objects.type \n\t\t\t\t where " . $type_filter . $complete_str . " \n\t\t\t\t and (healingcrystals_project_objects.name is not null) \n\t\t\t\t and ( (healingcrystals_project_objects.name like '%" . addslashes($search_for) . "%') or ( " . $all_parts_in_name_string . " )  or ( " . $few_parts_in_name_string . " ) ) \n\t\t\t\t and healingcrystals_search_index.type='" . $type . "' \n\t\t\t\t and healingcrystals_project_objects.state='" . STATE_VISIBLE . "' " . (empty($search_object_type) ? "" : " and healingcrystals_project_objects.type='" . $search_object_type . "' ") . " )\n\t\t\t\t UNION \n\t\t\t\t (select distinct(healingcrystals_project_objects.id), healingcrystals_sort_order_for_search.sort_order, if(healingcrystals_project_objects.completed_on is null, '0', '1'), if(healingcrystals_project_objects.body like '%" . addslashes($search_for) . "%','2', if(" . $all_parts_in_body_string . ",'4',if(" . $few_parts_in_body_string . ",'6','99'))) as new_order, healingcrystals_project_objects.* \n\t\t  \t\t from healingcrystals_project_objects " . (!empty($search_under_project_id) ? " inner join healingcrystals_projects on (healingcrystals_project_objects.project_id=healingcrystals_projects.id and  healingcrystals_project_objects.project_id='" . (int) $search_under_project_id . "') " : " ") . " inner join healingcrystals_search_index on healingcrystals_project_objects.id=healingcrystals_search_index.object_id \n\t\t  \t\t left join healingcrystals_sort_order_for_search on healingcrystals_sort_order_for_search.type=healingcrystals_project_objects.type \n\t\t\t\t where " . $type_filter . $complete_str . " \n\t\t\t\t and ( (healingcrystals_project_objects.body like '%" . addslashes($search_for) . "%') or ( " . $all_parts_in_body_string . " ) or ( " . $few_parts_in_body_string . " ) ) \n\t\t\t\t and (healingcrystals_project_objects.name is null or healingcrystals_project_objects.name='') \n\t\t\t\t and healingcrystals_search_index.type='" . $type . "' \n\t\t\t\t and healingcrystals_project_objects.state='" . STATE_VISIBLE . "' " . (empty($search_object_type) ? "" : " and healingcrystals_project_objects.type='" . $search_object_type . "' ") . " )";
             $count_query_main = "(select * from healingcrystals_project_objects " . (!empty($search_under_project_id) ? " inner join healingcrystals_projects on (healingcrystals_project_objects.project_id=healingcrystals_projects.id and  healingcrystals_project_objects.project_id='" . (int) $search_under_project_id . "') " : " ") . " inner join healingcrystals_search_index on healingcrystals_project_objects.id=healingcrystals_search_index.object_id \n\t\t  \t\t left join healingcrystals_sort_order_for_search on healingcrystals_sort_order_for_search.type=healingcrystals_project_objects.type \n\t\t\t\t where " . $type_filter . $complete_str . " and (healingcrystals_project_objects.name is not null) \n\t\t\t\t and ( (healingcrystals_project_objects.name like '%" . addslashes($search_for) . "%' ) or ( " . $all_parts_in_name_string . " ) or ( " . $few_parts_in_name_string . " ) ) \n\t\t\t\t and healingcrystals_search_index.type='" . $type . "' \n\t\t\t\t and healingcrystals_project_objects.state='" . STATE_VISIBLE . "' " . (empty($search_object_type) ? "" : " and healingcrystals_project_objects.type='" . $search_object_type . "' ") . " )\n\t\t\t\t UNION \n\t\t\t\t (select * from healingcrystals_project_objects " . (!empty($search_under_project_id) ? " inner join healingcrystals_projects on (healingcrystals_project_objects.project_id=healingcrystals_projects.id and  healingcrystals_project_objects.project_id='" . (int) $search_under_project_id . "') " : " ") . " inner join healingcrystals_search_index on healingcrystals_project_objects.id=healingcrystals_search_index.object_id \n\t\t  \t\t left join healingcrystals_sort_order_for_search on healingcrystals_sort_order_for_search.type=healingcrystals_project_objects.type \n\t\t\t\t where " . $type_filter . $complete_str . "\n\t\t\t\t and ( (healingcrystals_project_objects.body like '%" . addslashes($search_for) . "%' ) or ( " . $all_parts_in_body_string . " ) or ( " . $few_parts_in_body_string . " ) ) \n\t\t\t\t and (healingcrystals_project_objects.name is null or healingcrystals_project_objects.name='')  \n\t\t\t\t and healingcrystals_search_index.type='" . $type . "' \n\t\t\t\t and healingcrystals_project_objects.state='" . STATE_VISIBLE . "' " . (empty($search_object_type) ? "" : " and healingcrystals_project_objects.type='" . $search_object_type . "' ") . " )";
         }
         $result = mysql_query($query_main, $link);
         $count_result = mysql_query($count_query_main, $link);
         $count = mysql_num_rows($count_result);
         $total_items = mysql_num_rows($result);
         //mysql_query("insert into testing (content, date_added) values ('" . mysql_real_escape_string($query_main) . "', now())");
         if ($total_items) {
             $rows = array();
             $items = array();
             //$items = ProjectObjects::findBySQL("SELECT $project_objects_table.* FROM $project_objects_table, $search_index_table WHERE $type_filter AND MATCH ($search_index_table.content) AGAINST (? IN BOOLEAN MODE) AND $project_objects_table.id = $search_index_table.object_id AND $search_index_table.type = ? AND state >= ? AND visibility >= ? LIMIT $offset, $per_page", array($search_for, $type, STATE_VISIBLE, $user->getVisibility()));
             $ids = array();
             //BOF:mod 20110706 ticketid222
             /*
             //EOF:mod 20110706 ticketid222
             $query = $query_main . " order by 2, 1 LIMIT " . $offset . " ," . $per_page;
             //BOF:mod 20110706 ticketid222
             */
             //BOF:mod 20120711
             if (empty($datesort)) {
                 //EOF:mod 20120711
                 $query = $query_main . " order by new_order ASC, 2, 1, created_on desc LIMIT " . $offset . " ," . $per_page;
                 //BOF:mod 20120711
             } elseif ($datesort == 'a') {
                 $query = $query_main . " order by created_on, new_order ASC, 2, 1 LIMIT " . $offset . " ," . $per_page;
             } elseif ($datesort == 'd') {
                 $query = $query_main . " order by created_on desc, new_order ASC, 2, 1 LIMIT " . $offset . " ," . $per_page;
             }
             //EOF:mod 20120711
             //EOF:mod 20110706 ticketid222
             $result = mysql_query($query, $link);
             while ($info = mysql_fetch_assoc($result)) {
                 $ids[] = $info['id'];
                 $rows[] = $info;
             }
             foreach ($rows as $row) {
                 $item_class = array_var($row, 'type');
                 $item = new $item_class();
                 $item->loadFromRow($row);
                 $add_item = true;
                 if ($_GET['complete'] != '1') {
                     if ($item->getParentType() == 'Page') {
                         $temp_page = new Page($item->getParentId());
                         $is_archived = $temp_page->getIsArchived();
                         if ($is_archived) {
                             $add_item = false;
                         }
                     }
                     if ($add_item) {
                         $temp_obj = new ProjectObject($item->getParentId());
                         if ($temp_obj->isCompleted()) {
                             $add_item = false;
                         }
                     }
                 }
                 if ($add_item) {
                     $items[] = $item;
                 }
             }
             if (empty($search_object_type)) {
                 //$items = ProjectObjects::findBySQL("SELECT $project_objects_table.* FROM $project_objects_table, $search_index_table WHERE $type_filter AND MATCH ($search_index_table.content) AGAINST (? IN BOOLEAN MODE) AND $project_objects_table.id = $search_index_table.object_id AND $search_index_table.type = ? AND state >= ? AND visibility >= ? LIMIT $offset, $per_page", array($search_for, $type, STATE_VISIBLE, $user->getVisibility()));
             } else {
                 //$items = ProjectObjects::findBySQL("SELECT $project_objects_table.* FROM $project_objects_table, $search_index_table WHERE $type_filter AND MATCH ($search_index_table.content) AGAINST (? IN BOOLEAN MODE) AND $project_objects_table.id = $search_index_table.object_id AND $search_index_table.type = ? AND state >= ? AND visibility >= ? AND $project_objects_table.type = ? LIMIT $offset, $per_page", array($search_for, $type, STATE_VISIBLE, $user->getVisibility(), $search_object_type));
             }
             //mysql_query("insert into healingcrystals_testing (query, fired_at) values ('" . mysql_real_escape_string($query) . "', now())", $link);
         } else {
             $items = null;
         }
         // if
         mysql_close($link);
         return array($items, new Pager($page, $total_items, $per_page), $count);
         // Search for projects
     } elseif ($type == 'Project') {
         $project_ids = Projects::findProjectIdsByUser($user, null, true);
         if (!is_foreachable($project_ids)) {
             return array(null, new Pager(1, 0, $per_page));
         }
         // if
         $projects_table = TABLE_PREFIX . 'projects';
         $total_items = (int) array_var(db_execute_one("SELECT COUNT({$projects_table}.id) AS 'row_count' FROM {$projects_table}, {$search_index_table} WHERE {$projects_table}.id IN (?) AND MATCH ({$search_index_table}.content) AGAINST (? IN BOOLEAN MODE) AND {$projects_table}.id = {$search_index_table}.object_id AND {$search_index_table}.type = ?", $project_ids, $search_for, 'Project'), 'row_count');
         if ($total_items) {
             $items = Projects::findBySQL("SELECT * FROM {$projects_table}, {$search_index_table} WHERE {$projects_table}.id IN (?) AND MATCH ({$search_index_table}.content) AGAINST (? IN BOOLEAN MODE) AND {$projects_table}.id = {$search_index_table}.object_id AND {$search_index_table}.type = ? LIMIT {$offset}, {$per_page}", array($project_ids, $search_for, 'Project'));
         } else {
             $items = null;
         }
         // if
         return array($items, new Pager($page, $total_items, $per_page));
         // Search for users
     } elseif ($type == 'User') {
         $user_ids = $user->visibleUserIds();
         if (!is_foreachable($user_ids)) {
             return array(null, new Pager(1, 0, $per_page));
         }
         // if
         $users_table = TABLE_PREFIX . 'users';
         $total_items = (int) array_var(db_execute_one("SELECT COUNT({$users_table}.id) AS 'row_count' FROM {$users_table}, {$search_index_table} WHERE {$users_table}.id IN (?) AND MATCH ({$search_index_table}.content) AGAINST (? IN BOOLEAN MODE) AND {$users_table}.id = {$search_index_table}.object_id AND {$search_index_table}.type = ?", $user_ids, $search_for, 'User'), 'row_count');
         if ($total_items) {
             $items = Users::findBySQL("SELECT * FROM {$users_table}, {$search_index_table} WHERE {$users_table}.id IN (?) AND MATCH ({$search_index_table}.content) AGAINST (? IN BOOLEAN MODE) AND {$users_table}.id = {$search_index_table}.object_id AND {$search_index_table}.type = ? LIMIT {$offset}, {$per_page}", array($user_ids, $search_for, 'User'));
         } else {
             $items = null;
         }
         // if
         return array($items, new Pager($page, $total_items, $per_page));
         // Unknown search type
     } else {
         return array(null, new Pager(1, 0, $per_page));
     }
     // if
 }
 /**
  * Validate before save
  *
  * @param ValidationErrors $errors
  * @return null
  */
 function validate(&$errors)
 {
     if (!$this->validatePresenceOf('name', 3)) {
         $errors->addError(lang('Checklist summary is required'), 'name');
     }
     // if
     parent::validate($errors, true);
 }
 function move_to()
 {
     $gettype = $_GET['gettype'];
     $team_id = $_GET['team_id'];
     $project_id = $_GET['project_id'];
     $ticket_id = $_GET['ticket_id'];
     $move_to_object_id = $_GET['move_to_object_id'];
     if (!empty($gettype)) {
         $this->smarty->assign('gettype', $gettype);
         switch ($gettype) {
             case 'projects':
                 $projects = array();
                 if (!empty($team_id)) {
                     $project_obj = new Project($team_id);
                     //$projects = Milestones::findByProject($project_obj, $this->logged_user);
                     $projects = Milestones::findActiveByProject($project_obj, STATE_VISIBLE, VISIBILITY_NORMAL, 'name', '', '-1');
                 }
                 $this->smarty->assign('projects', $projects);
                 break;
             case 'tickets':
                 $tickets = array();
                 if (!empty($project_id)) {
                     $milestone_obj = new Milestone($project_id);
                     //$tickets = Tickets::findByMilestone($milestone_obj, STATE_VISIBLE, $this->logged_user->getVisibility());
                     $tickets = Tickets::findOpenByMilestone($milestone_obj, STATE_VISIBLE, $this->logged_user->getVisibility());
                 }
                 $this->smarty->assign('tickets', $tickets);
                 break;
             case 'pages':
                 $pages_with_milestone = array();
                 $pages_with_project = array();
                 if (!empty($team_id)) {
                     $project_obj = new Project($team_id);
                     //$pages_with_project = Pages::findByProjectWithoutMilestoneAssociation($project_obj, STATE_VISIBLE, $this->logged_user->getVisibility());
                     $pages_with_project = Pages::findUnarchivedByProjectWithoutMilestoneAssociation($project_obj, STATE_VISIBLE, $this->logged_user->getVisibility());
                 } elseif (!empty($project_id)) {
                     if (!empty($project_id)) {
                         $milestone_obj = new Milestone($project_id);
                         $team_id = $milestone_obj->getProjectId();
                         //$pages_with_milestone = Pages::findByMilestone($milestone_obj, STATE_VISIBLE, $this->logged_user->getVisibility());
                         $pages_with_milestone = Pages::findUnarchivedByMilestone($milestone_obj, STATE_VISIBLE, $this->logged_user->getVisibility());
                         $project_obj = new Project($team_id);
                         //$pages_with_project = Pages::findByProjectWithoutMilestoneAssociation($project_obj, STATE_VISIBLE, $this->logged_user->getVisibility());
                         $pages_with_project = Pages::findUnarchivedByProjectWithoutMilestoneAssociation($project_obj, STATE_VISIBLE, $this->logged_user->getVisibility());
                     }
                 }
                 $this->smarty->assign('pages_with_milestone', $pages_with_milestone);
                 $this->smarty->assign('pages_with_project', $pages_with_project);
                 break;
             case 'action':
                 $move_to_object = new ProjectObject($move_to_object_id);
                 $link = mysql_connect(DB_HOST, DB_USER, DB_PASS);
                 mysql_select_db(DB_NAME);
                 mysql_query("update healingcrystals_attachments set parent_id='" . $move_to_object->getId() . "', parent_type='" . $move_to_object->getType() . "' where id='" . $this->active_attachment->getId() . "'");
                 mysql_close($link);
                 $type = $move_to_object->getType();
                 $obj = new $type($move_to_object_id);
                 $link = 'Attachment Moved: <a href="' . $obj->getViewUrl() . '">Click to View</a>';
                 $this->smarty->assign('link', $link);
                 break;
         }
     } else {
         $teams = Projects::findNamesByUser($this->logged_user);
         $this->smarty->assign('teams', $teams);
     }
     $parent = $this->active_attachment->getParent();
     $this->smarty->assign('cur_project_id', $parent->getProjectId());
     $this->smarty->assign('cur_attachment_id', $this->active_attachment->getId());
 }
 /**
  * Add new entry to the log
  *
  * @param ProjectObject $object
  * @param User $by
  * @param string $comment
  * @return null
  */
 function log($object, $by = null, $comment = null)
 {
     $this->setType(get_class($this));
     $this->setObjectId($object->getId());
     $this->setProjectId($object->getProjectId());
     if ($by === null) {
         $by = get_logged_user();
     }
     // if
     $this->setCreatedBy($by);
     $this->setCreatedOn(new DateTimeValue());
     if ($comment) {
         $this->setComment($comment);
     }
     // if
     return $this->save();
 }
 /**
  * Returns true if $user can create a new repository in $project
  *
  * @param User $user
  * @param Project $project
  * @return boolean
  */
 function canAdd($user, $project)
 {
     return ProjectObject::canAdd($user, $project, 'github_repository');
 }
 /**
  * View specific page
  *
  * @param void
  * @return null
  */
 function view()
 {
     //BOF:mod 20120814
     $redirect_to_page_id = '';
     switch ($this->active_page->getId()) {
         case '22836':
             $redirect_to_page_id = '26019';
             break;
         case '21394':
             $redirect_to_page_id = '26136';
             break;
         case '21400':
             $redirect_to_page_id = '26137';
             break;
         case '21401':
             $redirect_to_page_id = '26138';
             break;
         case '24845':
             $redirect_to_page_id = '26139';
             break;
         case '24859':
             $redirect_to_page_id = '26140';
             break;
         case '24867':
             $redirect_to_page_id = '26141';
             break;
         case '25498':
             $redirect_to_page_id = '26142';
             break;
     }
     if (!empty($redirect_to_page_id)) {
         $this->redirectToUrl(assemble_url('project_page', array('project_id' => TASK_LIST_PROJECT_ID, 'page_id' => $redirect_to_page_id)));
     }
     //EOF:mod 20120814
     if ($this->active_page->isNew()) {
         $this->httpError(HTTP_ERR_NOT_FOUND, null, true, $this->request->isApiCall());
     }
     // if
     if (!$this->active_page->canView($this->logged_user)) {
         $this->httpError(HTTP_ERR_FORBIDDEN, null, true, $this->request->isApiCall());
     }
     // if
     if ($this->request->isApiCall()) {
         $this->serveData($this->active_page, 'page', array('describe_comments' => true, 'describe_tasks' => true, 'describe_attachments' => true, 'describe_subpages' => true, 'describe_revisions' => true));
     } else {
         ProjectObjectViews::log($this->active_page, $this->logged_user);
         $page = (int) $this->request->get('page');
         if ($page < 1) {
             $page = 1;
         }
         // if
         $show_all = $this->request->get('show_all');
         if (!empty($show_all) && $show_all == '1' && !isset($_GET['comment_id'])) {
             $comments = null;
             $pagination = null;
         } else {
             $show_all = '';
             list($comments, $pagination) = $this->active_page->paginateComments($page, $this->active_page->comments_per_page, $this->logged_user->getVisibility());
         }
         $comments_only_mode = $this->request->get('comments_only_mode');
         if ($comments_only_mode) {
             $this->smarty->assign(array('_object_comments_comments' => $comments, 'pagination' => $pagination, '_counter' => ($page - 1) * $this->active_page->comments_per_page));
             echo $this->smarty->fetch(get_template_path('_object_comments_ajax', 'comments', RESOURCES_MODULE));
             exit;
         }
         $scroll_to_comment = $this->request->get('comment_id');
         /*if (!empty($scroll_to_comment)){
         			for($i=0; $i<count($comments); $i++){
         				if ($comments[$i]->getId()==$scroll_to_comment){
         					$scroll_to_comment = '';
         					break;
         				}
         			}
         		}*/
         $dID = $_GET['dID'];
         if (!empty($dID)) {
             $this->active_page->changeDepartmentTo($dID);
         }
         $pID = $_GET['pID'];
         if (!empty($pID)) {
             $this->active_page->setMilestoneId($pID);
             $this->active_page->save();
             $this->active_page->changeDepartmentTo(ProjectObject::getDepartmentId($pID));
         }
         $this->smarty->assign(array('parent' => $this->active_page->getParent(), 'subpages' => $this->active_page->getSubpages($this->logged_user->getVisibility()), 'versions' => $this->active_page->getVersions(), 'comments' => $comments, 'pagination' => $pagination, 'subscribers' => $this->active_page->getSubscribers(), 'current_user_id' => $this->logged_user->getId(), 'object_id' => $this->active_page->getId(), 'scroll_to_comment' => $scroll_to_comment, 'show_all' => $show_all));
     }
     // if
 }
 /**
  * Get project section URL
  *
  * @param ProjectObject $project
  * @return string
  */
 function getProjectCalendarUrl($project)
 {
     return assemble_url('project_calendar', array('project_id' => $project->getId()));
 }
 /**
  * Validate before save
  *
  * @param ValidationErrors $errors
  * @return null
  */
 function validate(&$errors)
 {
     if (!$this->validatePresenceOf('name', 3)) {
         $errors->addError(lang('Milestone name is required'), 'name');
     }
     // if
     /*
     if(!$this->validatePresenceOf('start_on')) {
       $errors->addError(lang('Start date is required'), 'start_on');
     } // if
     
     if(!$this->validatePresenceOf('due_on')) {
       $errors->addError(lang('Due date is required'), 'due_on');
     } // if
     */
     $start_on = $this->getStartOn();
     $due_on = $this->getDueOn();
     if (instance_of($start_on, 'DateValue') && instance_of($due_on, 'DateValue')) {
         if (!empty($due_on->timestamp)) {
             if ($start_on->getTimestamp() > $due_on->getTimestamp()) {
                 $errors->addError(lang('Start date needs to be before due date'), 'date_range');
             }
             // if
         }
     }
     // if
     parent::validate($errors, true);
 }