/**
 * Render object tags
 *
 * Parameters:
 * 
 * - object - Selected object
 * - project - Selected project, if not present we'll get it from 
 *   $object->getProject()
 * 
 * @param array $params
 * @param Smarty $smarty
 * @return string
 */
function smarty_function_object_tags($params, &$smarty)
{
    $object = array_var($params, 'object');
    if (!instance_of($object, 'ProjectObject')) {
        return new InvalidParamError('object', $object, '$object is expected to be an instance of ProjectObject class', true);
    }
    // if
    $project = array_var($params, 'project');
    if (!instance_of($project, 'Project')) {
        $project = $object->getProject();
    }
    // if
    if (!instance_of($project, 'Project')) {
        return new InvalidParamError('project', $project, '$project is expected to be an instance of Project class', true);
    }
    // if
    $tags = $object->getTags();
    if (is_foreachable($tags)) {
        $prepared = array();
        foreach ($tags as $tag) {
            if (trim($tag)) {
                $prepared[] = '<a href="' . Tags::getTagUrl($tag, $project) . '">' . clean($tag) . '</a>';
            }
            // if
        }
        // if
        return implode(', ', $prepared);
    } else {
        return '<span class="no_tags">' . lang('-- No tags --') . '</span>';
    }
    // if
}
	static function format_single_file($object_info, $id_prefix="") {
		$html .= "<table class='file_info_container' id='{$id_prefix}file_info_container' cellpadding='0' cellspacing='5'>";
		
		$html .= "<tr><td><img class='view_file_icon' src='".array_var($object_info, 'icon_l')."' alt='icon' /></td>";
		$html .= "<td><div class='file_name'>".array_var($object_info, 'name')."</div>";
		
		$upd_by = array_var($object_info, 'updated_by') . " - ".array_var($object_info, 'updated_on');
		$html .= "<div class='file_updated'>".lang('modified by').": $upd_by</div></td>";
		$html .= "</tr></table>";
		
		$revisions = array_var($object_info, 'revisions');
		if (is_array($revisions)) {
			$html .= "<div class='revisions_title'>".lang('revisions')."</div>";
			$html .= "<table class='revisions_container' id='{$id_prefix}revisions_container' cellpadding='0' cellspacing='5'>";
			foreach ($revisions as $revision) {
				$html .= "<tr class='revision_info_container'>";
				$html .= "<td class='revision_info_number'>#".array_var($revision, 'number')."</td>";
				$html .= "<td class='revision_info_name'>".array_var($revision, 'created_by')." - ".array_var($revision, 'created_on')."</td>";
				$html .= "<td class='revision_info_download'>".array_var($revision, 'download_link')."</td>";
				if (strlen(array_var($revision, 'comment', '')) > 0)
					$html .= "</tr><tr><td colspan='3' class='revision_info_comment'>".lang('comment').": ".array_var($revision, 'comment')."</td>";
				$html .= "</tr>";
			}
			$html .= "</table>";
		}
		
		return $html;
	}
 /**
  * Ajax that will return response from command line
  *
  * @param void
  * @return null
  */
 function test_svn()
 {
     $path = array_var($_GET, 'svn_path', null);
     $check_executable = RepositoryEngine::executableExists($path);
     echo $check_executable === true ? 'true' : $check_executable;
     die;
 }
/**
 * Render select page control
 * 
 * Parameters:
 * 
 * - project - Parent project
 * - value - ID of selected page
 *
 * @param array $params
 * @param Smarty $smarty
 * @return string
 */
function smarty_function_select_page($params, &$smarty)
{
    $project = array_var($params, 'project', null, true);
    if (!instance_of($project, 'Project')) {
        return new InvalidParamError('project', $project, '$project is expected to be an instance of Project class', true);
    }
    // if
    $user = array_var($params, 'user');
    if (!instance_of($user, 'User')) {
        return new InvalidParamError('user', $user, '$user is exepcted to be an instance of User class', true);
    }
    // if
    $options = array();
    $value = array_var($params, 'value', null, true);
    $skip = array_var($params, 'skip');
    $categories = Categories::findByModuleSection($project, PAGES_MODULE, 'pages');
    if (is_foreachable($categories)) {
        foreach ($categories as $category) {
            $option_attributes = $category->getId() == $value ? array('selected' => true) : null;
            $options[] = option_tag($category->getName(), $category->getId(), $option_attributes);
            $pages = Pages::findByCategory($category, STATE_VISIBLE, $user->getVisibility());
            if (is_foreachable($pages)) {
                foreach ($pages as $page) {
                    smarty_function_select_page_populate_options($page, $value, $user, $skip, $options, '- ');
                }
                // foreach
            }
            // if
        }
        // foreach
    }
    // if
    return select_box($options, $params);
}
Beispiel #5
0
 /**
  * This function will return specific connection. If $connection_name is NULL primary connection will be used
  *
  * @access public
  * @param string $connection_name Connection name, if NULL primary connection will be used
  * @return AbstractDBAdapter
  */
 static function connection($connection_name = null)
 {
     if (is_null($connection_name)) {
         $connection_name = self::getPrimaryConnection();
     }
     return array_var(self::$connections, $connection_name);
 }
/**
 * Display user name with a link to users profile
 * 
 * - user - User - We create link for this User
 * - short - boolean - Use short display name
 * 
 * @param array $params
 * @param Smarty $smarty
 * @return string
 */
function smarty_function_user_link($params, &$smarty)
{
    static $cache = array();
    $user = array_var($params, 'user');
    $short = array_var($params, 'short', false);
    // User instance
    if (instance_of($user, 'User')) {
        if (!isset($cache[$user->getId()])) {
            //BOF:mod 20121030
            /*
            //EOF:mod 20121030
                    $cache[$user->getId()] = '<a href="' . $user->getViewUrl() . '" class="user_link">' . clean($user->getDisplayName($short)) . '</a>';
            //BOF:mod 20121030
            */
            $cache[$user->getId()] = '<a href="' . $user->getViewUrl() . '" class="user_link">' . clean($user->getDisplayName()) . '</a>';
            //EOF:mod 20121030
        }
        // if
        return $cache[$user->getId()];
        // AnonymousUser instance
    } elseif (instance_of($user, 'AnonymousUser') && trim($user->getName()) && is_valid_email($user->getEmail())) {
        return '<a href="mailto:' . $user->getEmail() . '" class="anonymous_user_link">' . clean($user->getName()) . '</a>';
        // Unknown user
    } else {
        return '<span class="unknow_user_link unknown_object_link">' . clean(lang('Unknown user')) . '</span>';
    }
    // if
}
/**
 * Render comments
 * 
 * Parameters:
 * 
 * - comments - comments that needs to be rendered
 * - page - current_page
 * - total_pages - total pages
 * - counter - counter for comment #
 * - url - base URL for link assembly
 * - parent - parent object
 *
 * @param array $params
 * @param Smarty $smarty
 * @return string
 */
function smarty_function_mobile_access_object_comments($params, &$smarty)
{
    $url_params = '';
    if (is_foreachable($params)) {
        foreach ($params as $k => $v) {
            if (strpos($k, 'url_param_') !== false && $v) {
                $url_params .= '&amp;' . substr($k, 10) . '=' . $v;
            }
            // if
        }
        // foreach
    }
    // if
    $object = array_var($params, 'object');
    if (!instance_of($object, 'ProjectObject')) {
        return new InvalidParamError('object', $object, '$object is expected to be an instance of ProjectObject class', true);
    }
    // if
    $user = array_var($params, 'user');
    if (!instance_of($user, 'User')) {
        return new InvalidParamError('object', $user, '$user is expected to be an instance of User class', true);
    }
    // if
    $page = array_var($params, 'page', 1);
    $page = (int) array_var($_GET, 'page');
    if ($page < 1) {
        $page = 1;
    }
    // if
    $counter = array_var($params, 'counter', 1);
    $counter = ($page - 1) * $object->comments_per_page + $counter;
    list($comments, $pagination) = $object->paginateComments($page, $object->comments_per_page, $user->getVisibility());
    $smarty->assign(array("_mobile_access_comments_comments" => $comments, "_mobile_access_comments_paginator" => $pagination, "_mobile_access_comments_url" => mobile_access_module_get_view_url($object), "_mobile_access_comments_url_params" => $url_params, "_mobile_access_comments_counter" => $counter, "_mobile_access_comments_show_counter" => array_var($params, 'show_counter', true)));
    return $smarty->fetch(get_template_path('_object_comments', null, MOBILE_ACCESS_MODULE));
}
/**
 * Render object assignees list
 *
 * @param array $params
 * @param Smarty $smarty
 * @return string
 */
function smarty_function_object_departments($params, &$smarty)
{
    $resp = '--';
    $object = array_var($params, 'object');
    if (!instance_of($object, 'ProjectObject')) {
        return new InvalidParamError('object', $object, '$object is expected to be an instance of ProjectObject class', true);
    }
    // if
    $link = mysql_connect(DB_HOST, DB_USER, DB_PASS);
    mysql_select_db(DB_NAME, $link);
    $query = "select a.category_name, a.id from \n\t\t\t healingcrystals_project_milestone_categories a \n\t\t\t inner join healingcrystals_project_object_categories b on b.category_id=a.id \n\t\t\t inner join healingcrystals_project_objects c on c.id=b.object_id where \n\t\t\t c.id='" . $object->getId() . "' order by a.category_name";
    $result = mysql_query($query, $link);
    if (mysql_num_rows($result)) {
        $resp = '';
        while ($info = mysql_fetch_assoc($result)) {
            if (instance_of($object, 'Milestone')) {
                $resp .= '<a href="' . assemble_url('project_milestones', array('project_id' => $object->getProjectId())) . '&category_id=' . $info['id'] . '">' . $info['category_name'] . '</a>, ';
            } elseif (instance_of($object, 'Ticket')) {
                $resp .= '<a href="' . assemble_url('project_tickets', array('project_id' => $object->getProjectId())) . '&department_id=' . $info['id'] . '">' . $info['category_name'] . '</a>, ';
            } elseif (instance_of($object, 'Page')) {
                $resp .= '<a href="' . assemble_url('project_pages', array('project_id' => $object->getProjectId())) . '&category_id=' . $info['id'] . '">' . $info['category_name'] . '</a>, ';
            } else {
                $resp .= $info['category_name'] . ', ';
            }
        }
        $resp = substr($resp, 0, -2);
    }
    mysql_close($link);
    return $resp;
}
function smarty_function_object_department_selection($params, &$smarty)
{
    $object = array_var($params, 'object');
    if (!instance_of($object, 'ProjectObject')) {
        return new InvalidParamError('object', $object, '$object is not valid instance of ProjectObject class', true);
    }
    $select = '';
    $select = '<select onchange="modify_department_association(this);">';
    $select .= '<option value="">-- Select Department --</option>';
    $link = mysql_connect(DB_HOST, DB_USER, DB_PASS);
    mysql_select_db(DB_NAME);
    $selected_department_id = '';
    $query = mysql_query("select category_id from healingcrystals_project_object_categories where object_id='" . $object->getId() . "'");
    if (mysql_num_rows($query)) {
        $info = mysql_fetch_assoc($query);
        $selected_department_id = $info['category_id'];
    }
    $query = mysql_query("select id, category_name from healingcrystals_project_milestone_categories where project_id='" . $object->getProjectId() . "' order by category_name");
    while ($entry = mysql_fetch_assoc($query)) {
        $select .= '<option value="' . $entry['id'] . '" ' . ($selected_department_id == $entry['id'] ? ' selected ' : '') . ' >' . $entry['category_name'] . '</option>';
    }
    mysql_close($link);
    $select .= '</select>';
    return $select;
}
/**
 * Render object assignees list
 *
 * @param array $params
 * @param Smarty $smarty
 * @return string
 */
function smarty_function_mobile_access_object_assignees($params, &$smarty)
{
    $object = array_var($params, 'object');
    if (!instance_of($object, 'ProjectObject')) {
        return new InvalidParamError('object', $object, '$object is expected to be an instance of ProjectObject class', true);
    }
    // if
    $owner = $object->getResponsibleAssignee();
    if (!instance_of($owner, 'User')) {
        Assignments::deleteByObject($object);
        return lang('No one is responsible');
    }
    // if
    require_once SYSTEM_MODULE_PATH . '/helpers/function.user_link.php';
    $other_assignees = array();
    $assignees = $object->getAssignees();
    if (is_foreachable($assignees)) {
        foreach ($assignees as $assignee) {
            if ($assignee->getId() != $owner->getId()) {
                $other_assignees[] = '<a href="' . mobile_access_module_get_view_url($assignee) . '">' . clean($assignee->getName()) . '</a>';
            }
            // if
        }
        // foreach
    }
    // if
    if (count($other_assignees)) {
        return '<a href="' . mobile_access_module_get_view_url($owner) . '">' . clean($owner->getName()) . '</a> ' . lang('is responsible') . '. ' . lang('Other assignees') . ': ' . implode(', ', $other_assignees);
    } else {
        return '<a href="' . mobile_access_module_get_view_url($owner) . '">' . clean($owner->getName()) . '</a> ' . lang('is responsible') . '.';
    }
    // if
}
/**
 * Render attach file to an object control
 * 
 * @param array $params
 * @param Smarty $smarty
 * @return string
 */
function smarty_function_attach_files($params, &$smarty)
{
    static $ids = array();
    $id = array_var($params, 'id');
    if (empty($id)) {
        $counter = 1;
        do {
            $id = 'attach_files_' . $id++;
        } while (in_array($id, $ids));
    }
    // if
    $ids[] = $id;
    $max_files = (int) array_var($params, 'max_files', 1, true);
    if ($max_files < 1) {
        $max_files = 1;
    }
    // if
    require_once SMARTY_PATH . '/plugins/modifier.filesize.php';
    if ($max_files == 1) {
        $max_upload_size_message = lang('Max size of file that you can upload is :size', array('size' => smarty_modifier_filesize(get_max_upload_size())));
    } else {
        $max_upload_size_message = lang('Max total size of files you can upload is :size', array('size' => smarty_modifier_filesize(get_max_upload_size())));
    }
    // if
    return '<div class="attach_files" id="' . $id . '" max_files="' . $max_files . '"><p class="attach_files_max_size details">' . $max_upload_size_message . '</p></div><script type="text/javascript">App.resources.AttachFiles.init("' . $id . '")</script>';
}
 function get_custom_properties()
 {
     $object_type = array_var($_GET, 'object_type');
     if ($object_type) {
         $cp = CustomProperties::getAllCustomPropertiesByObjectType($object_type);
         $customProperties = array();
         foreach ($cp as $custom) {
             $prop = array();
             $prop['id'] = $custom->getId();
             $prop['name'] = $custom->getName();
             $prop['object_type'] = $custom->getObjectTypeId();
             $prop['description'] = $custom->getDescription();
             $prop['type'] = $custom->getType();
             $prop['values'] = $custom->getValues();
             $prop['default_value'] = $custom->getDefaultValue();
             $prop['required'] = $custom->getIsRequired();
             $prop['multiple_values'] = $custom->getIsMultipleValues();
             $prop['visible_by_default'] = $custom->getVisibleByDefault();
             $prop['co_types'] = '';
             //CustomPropertiesByCoType::instance()->getCoTypesIdsForCpCSV($custom->getId());
             $customProperties[] = $prop;
         }
         ajx_current("empty");
         ajx_extra_data(array("custom_properties" => $customProperties));
     }
 }
/**
 * Join items
 * 
 * array('Peter', 'Joe', 'Adam') will be join like:
 * 
 * 'Peter, Joe and Adam
 * 
 * where separators can be defined as paremeters.
 * 
 * Parements:
 * 
 * - items - array of items that need to be join
 * - separator - used to separate all elements except the last one. ', ' by 
 *   default
 * - final_separator - used to separate last element from the rest of the 
 *   string. ' and ' by default
 *
 * @param array $params
 * @return string
 */
function smarty_function_join($params, &$smarty)
{
    $items = array_var($params, 'items');
    $separator = array_var($params, 'separator', ', ');
    $final_separator = array_var($params, 'final_separator', lang(' and '));
    if (is_foreachable($items)) {
        $result = '';
        $items_count = count($items);
        $counter = 0;
        foreach ($items as $item) {
            $counter++;
            if ($counter < $items_count - 1) {
                $result .= $item . $separator;
            } elseif ($counter == $items_count - 1) {
                $result .= $item . $final_separator;
            } else {
                $result .= $item;
            }
            // if
        }
        // if
        return $result;
    } else {
        return $items;
    }
    // if
}
/**
 * Render inline select assignees
 * 
 * Parameters:
 * 
 * - ticket_id
 * - user_id
 * - name
 * @param array $params
 * @param Smarty $smarty
 * @return string
 */
function smarty_function_set_assignee_actionrequest_html($params, &$smarty)
{
    $object_id = array_var($params, 'object_id');
    $user_id = array_var($params, 'user_id');
    $flag_set = false;
    $priority = -99;
    $link = mysql_connect(DB_HOST, DB_USER, DB_PASS);
    mysql_select_db(DB_NAME);
    $query = "select flag_actionrequest, priority_actionrequest from healingcrystals_assignments_flag_fyi_actionrequest where user_id='" . $user_id . "' and object_id='" . $object_id . "'";
    $result = mysql_query($query, $link);
    if (mysql_num_rows($result)) {
        $info = mysql_fetch_assoc($result);
        if ($info['flag_actionrequest'] == '1') {
            $flag_set = true;
        }
        $priority = $info['priority_actionrequest'];
    }
    mysql_close($link);
    $resp = '&nbsp;<input type="checkbox" name="assignee[flag_actionrequest][]" value="' . $user_id . '" class="input_checkbox" ' . ($flag_set ? ' checked="true" ' : '') . '  onclick="auto_select_checkboxes(this);" />
			 <select name="assignee[priority_actionrequest][]" onchange="auto_select_checkboxes(this);" style="display:none;">
			 	<option value="' . $user_id . '_-99"' . (is_null($priority) || $priority == '-99' ? ' selected ' : '') . '>-- Set Priority --</option>
			 	<option value="' . $user_id . '_' . PRIORITY_HIGHEST . '" ' . ($priority == PRIORITY_HIGHEST ? ' selected ' : '') . '>Highest Priority</option>
			 	<option value="' . $user_id . '_' . PRIORITY_HIGH . '" ' . ($priority == PRIORITY_HIGH ? ' selected ' : '') . '>High Priority</option>
			 	<option value="' . $user_id . '_' . PRIORITY_NORMAL . '" ' . ($priority == PRIORITY_NORMAL ? ' selected ' : '') . '>Normal Priority</option>
			 	<option value="' . $user_id . '_' . PRIORITY_LOW . '" ' . ($priority == PRIORITY_LOW ? ' selected ' : '') . '>Low Priority</option>
			 	<option value="' . $user_id . '_' . PRIORITY_LOWEST . '" ' . ($priority == PRIORITY_LOWEST ? ' selected ' : '') . '>Lowest Priority</option>
			 </select>';
    return $resp;
}
/**
 * Render select parent object for provided project
 * 
 * Supported paramteres:
 * 
 * - types - type of of parent objects to be listed
 * - project - Instance of selected project (required)
 *
 * @param array $params
 * @param Smarty $smarty
 * @return string
 */
function smarty_function_select_project_object($params, &$smarty)
{
    $project = array_var($params, 'project');
    if (!instance_of($project, 'Project')) {
        return new InvalidParamError('project', $project, '$project is expected to be an instance of Project class', true);
    }
    // if
    $value = array_var($params, 'value');
    unset($params['project']);
    $types = array_var($params, 'types', null);
    if (!$types || !is_foreachable($types = explode(',', $types))) {
        $types = array('ticket', 'file', 'discussion', 'page');
    }
    // if
    $id_name_map = ProjectObjects::getIdNameMapForProject($project, $types);
    if (!is_foreachable($id_name_map)) {
        return false;
    }
    // if
    $sorted = array();
    foreach ($id_name_map as $object) {
        $option_attributes = $value == $object['id'] ? array('selected' => true) : null;
        $sorted[strtolower($object['type'])][] = option_tag($object['name'], $object['id'], $option_attributes);
    }
    // foreach
    if (is_foreachable($sorted)) {
        foreach ($sorted as $sorted_key => $sorted_values) {
            $options[] = option_group_tag($sorted_key, $sorted_values);
        }
        // foreach
    }
    // if
    return select_box($options, $params);
}
/**
 * Render object assignees list
 *
 * @param array $params
 * @param Smarty $smarty
 * @return string
 */
function smarty_function_object_owner($params, &$smarty)
{
    $object = array_var($params, 'object');
    if (!instance_of($object, 'ProjectObject')) {
        return new InvalidParamError('object', $object, '$object is expected to be an instance of ProjectObject class', true);
    }
    // if
    $users_table = TABLE_PREFIX . 'users';
    $assignments_table = TABLE_PREFIX . 'assignments';
    $rows = db_execute_all("SELECT {$assignments_table}.is_owner AS is_assignment_owner, {$users_table}.id AS user_id, {$users_table}.company_id, {$users_table}.first_name, {$users_table}.last_name, {$users_table}.email FROM {$users_table}, {$assignments_table} WHERE {$users_table}.id = {$assignments_table}.user_id AND {$assignments_table}.object_id = ? and {$assignments_table}.is_owner='1' ORDER BY {$assignments_table}.is_owner DESC", $object->getId());
    if (is_foreachable($rows)) {
        $owner = null;
        foreach ($rows as $row) {
            if (empty($row['first_name']) && empty($row['last_name'])) {
                $user_link = '<a href="' . assemble_url('people_company', array('company_id' => $row['company_id'])) . '#user' . $row['user_id'] . '">' . clean($row['email']) . '</a>';
            } else {
                $user_link = '<a href="' . assemble_url('people_company', array('company_id' => $row['company_id'])) . '#user' . $row['user_id'] . '">' . clean($row['first_name']) . '</a>';
            }
            // if
            $owner .= $user_link . '&nbsp;';
        }
        // foreach
    }
    // if
    if (empty($owner)) {
        $owner = '--';
    }
    // if
    return $owner;
}
/**
 * Render object reminder information
 *
 * @param array $params
 * @param Smarty $smarty
 * @return string
 */
function smarty_function_object_recurring_period($params, &$smarty)
{
    $ticket = array_var($params, 'object');
    if (!instance_of($ticket, 'Ticket')) {
        return 'N/A';
    }
    // if
    $link = mysql_connect(DB_HOST, DB_USER, DB_PASS);
    mysql_select_db(DB_NAME);
    $query = "select * from healingcrystals_project_object_misc where object_id='" . (int) $ticket->getId() . "'";
    $result = mysql_query($query, $link);
    if (mysql_num_rows($result)) {
        $info = mysql_fetch_assoc($result);
        $reminder_date = $info['reminder_date'];
        $recurring_period = $info['recurring_period'];
        $recurring_period_type = $info['recurring_period_type'];
    }
    mysql_close($link);
    $resp = '<form name="frmRecurringPeriod" action="' . $ticket->getEditUrl() . '&mode=recurring_period_update_mode" method=post>
                    <input type="text" name="recurring_period" value="' . $recurring_period . '" maxlength="5" style="width:50px;" onchange="this.form.submit();" />&nbsp;
                    <select name="recurring_period_type" style="width:80px;" onchange="this.form.submit();">
                        <option value="D" ' . ($recurring_period_type == 'D' ? ' selected ' : '') . '>Days</option>
			<option value="W" ' . ($recurring_period_type == 'W' ? ' selected ' : '') . '>Weeks</option>
			<option value="M" ' . ($recurring_period_type == 'M' ? ' selected ' : '') . '>Months</option>
			<option value="Y" ' . ($recurring_period_type == 'Y' ? ' selected ' : '') . '>Years</option>
                    </select>
		</form>';
    return $resp;
}
 /**
  * Returns true if the object blongs to the texmplate context ($memberIds)
  * 
  * @param ContentDataObject $object
  * @param array $memberIds
  */
 static function validateObjectContext($object, $memberIds)
 {
     $valid = true;
     // Dimensiones requeridas para el tipo de objecto
     $dimensions = Dimensions::getAllowedDimensions(self::instance()->getObjectTypeId());
     $requiredDimensions = array();
     foreach ($dimensions as $dim) {
         if ($dim['is_required']) {
             $requiredDimensions[$dim['dimension_id']] = $dim;
             // Performance, dim id in the array key  ! ! !
         }
     }
     // Miembros del Objeto
     $objMembers = $object->getMemberIds();
     // P/cada miembro
     foreach ($objMembers as $mid) {
         $member = Members::instance()->findById($mid);
         if ($member instanceof Member) {
             /* @var  $member Member */
             $did = $member->getDimensionId();
             // Si la dimension del miembro esta en la requeridas
             if (array_var($requiredDimensions, $did)) {
                 if (!in_array($mid, $memberIds)) {
                     $valid = false;
                 }
             }
         }
     }
     if (!$valid) {
         throw new DAOValidationError($this, array(lang("template members do not match object members")));
     }
 }
 /**
  * Show invoicing settings panel
  *
  * @param void
  * @return null
  */
 function index()
 {
     require_once INVOICING_MODULE_PATH . '/models/InvoicePdfGenerator.class.php';
     $paper_formats = array(PAPER_FORMAT_A4, PAPER_FORMAT_A3, PAPER_FORMAT_A5, PAPER_FORMAT_LETTER, PAPER_FORMAT_LEGAL);
     $paper_orientations = array(PAPER_ORIENTATION_PORTRAIT, PAPER_ORIENTATION_LANDSCAPE);
     $pdf_settings_data = $this->request->post('pdf_settings');
     if (!is_array($pdf_settings_data)) {
         $pdf_settings_data = array('paper_format' => ConfigOptions::getValue('invoicing_pdf_paper_format'), 'paper_orientation' => ConfigOptions::getValue('invoicing_pdf_paper_orientation'), 'header_text_color' => ConfigOptions::getValue('invoicing_pdf_header_text_color'), 'page_text_color' => ConfigOptions::getValue('invoicing_pdf_page_text_color'), 'border_color' => ConfigOptions::getValue('invoicing_pdf_border_color'), 'background_color' => ConfigOptions::getValue('invoicing_pdf_background_color'));
     }
     // if
     if ($this->request->isSubmitted()) {
         db_begin_work();
         ConfigOptions::setValue('invoicing_pdf_paper_format', array_var($pdf_settings_data, 'paper_format', 'A4'));
         ConfigOptions::setValue('invoicing_pdf_paper_orientation', array_var($pdf_settings_data, 'paper_orientation', 'Portrait'));
         ConfigOptions::setValue('invoicing_pdf_header_text_color', array_var($pdf_settings_data, 'header_text_color', '000000'));
         ConfigOptions::setValue('invoicing_pdf_page_text_color', array_var($pdf_settings_data, 'page_text_color', '000000'));
         ConfigOptions::setValue('invoicing_pdf_border_color', array_var($pdf_settings_data, 'border_color', '000000'));
         ConfigOptions::setValue('invoicing_pdf_background_color', array_var($pdf_settings_data, 'background_color', 'FFFFFF'));
         db_commit();
         flash_success('Successfully modified PDF settings');
         $this->redirectTo('admin_invoicing_pdf');
     }
     // if
     $this->smarty->assign(array('paper_formats' => $paper_formats, 'paper_orientations' => $paper_orientations, 'pdf_settings_data' => $pdf_settings_data));
 }
Beispiel #20
0
/**
 * Add single page action
 * 
 * You can use set of two params where first param is title and second one
 * is URL (the default set) and you can use array of actions as first
 * parram mapped like $title => $url
 *
 * @access public
 * @param string $title
 * @param string $url
 * @return PageAction
 */
function add_page_action()
{
    $args = func_get_args();
    if (!is_array($args) || !count($args)) {
        return;
    }
    // Array of data as first param mapped like $title => $url
    if (is_array(array_var($args, 0))) {
        foreach (array_var($args, 0) as $title => $url) {
            if (!empty($title) && !empty($url)) {
                PageActions::instance()->addAction(new PageAction($title, $url, array_var($args, 1)));
            }
            // if
        }
        // foreach
        // Four string params, title, URL and name
    } else {
        $title = array_var($args, 0);
        $url = array_var($args, 1);
        $name = array_var($args, 2);
        $target = array_var($args, 3);
        $attributes = array_var($args, 4);
        $isCommon = array_var($args, 5);
        if (!empty($title) && !empty($url)) {
            PageActions::instance()->addAction(new PageAction($title, $url, $name, $target, $attributes, $isCommon));
        }
        // if
    }
    // if
}
/**
 * Render object tasks section
 * 
 * Parameters:
 * 
 * - object - Selected project object
 *
 * @param array $params
 * @param Smarty $smarty
 * @return string
 */
function smarty_function_object_tasks($params, &$smarty)
{
    $object = array_var($params, 'object');
    if (!instance_of($object, 'ProjectObject')) {
        return new InvalidParamError('object', $object, '$object is expected to be an instance of ProjectObject class', true);
    }
    // if
    $open_tasks = $object->getOpenTasks();
    if (is_foreachable($open_tasks)) {
        foreach ($open_tasks as $open_task) {
            ProjectObjectViews::log($open_task, $smarty->get_template_vars('logged_user'));
        }
        // foreach
    }
    // if
    $completed_tasks = $object->getCompletedTasks(COMPLETED_TASKS_PER_OBJECT);
    if (is_foreachable($completed_tasks)) {
        foreach ($completed_tasks as $completed_task) {
            ProjectObjectViews::log($completed_task, $smarty->get_template_vars('logged_user'));
        }
        // foreach
    }
    // if
    $smarty->assign(array('_object_tasks_object' => $object, '_object_tasks_open' => $open_tasks, '_object_tasks_can_reorder' => (int) $object->canEdit($smarty->get_template_vars('logged_user')), '_object_tasks_completed' => $completed_tasks, '_object_tasks_completed_remaining' => $object->countCompletedTasks() - COMPLETED_TASKS_PER_OBJECT, '_object_tasks_skip_wrapper' => array_var($params, 'skip_wrapper', false), '_object_tasks_skip_head' => array_var($params, 'skip_head', false), '_object_tasks_force_show' => array_var($params, 'force_show', true)));
    return $smarty->fetch(get_template_path('_object_tasks', 'tasks', RESOURCES_MODULE));
}
 static function userHasSystemPermission(Contact $user, $system_permission)
 {
     if ($user->isAdministrator()) {
         return true;
     }
     if (array_var(self::$permission_cache, $user->getId())) {
         if (array_key_exists($system_permission, self::$permission_cache[$user->getId()])) {
             return array_var(self::$permission_cache[$user->getId()], $system_permission);
         }
     }
     if (array_var(self::$permission_group_ids_cache, $user->getId())) {
         $contact_pg_ids = self::$permission_group_ids_cache[$user->getId()];
     } else {
         $contact_pg_ids = ContactPermissionGroups::getPermissionGroupIdsByContactCSV($user->getId(), false);
         self::$permission_group_ids_cache[$user->getId()] = $contact_pg_ids;
     }
     $permission = self::findOne(array('conditions' => "`{$system_permission}` = 1 AND `permission_group_id` IN ({$contact_pg_ids})"));
     if (!array_var(self::$permission_cache, $user->getId())) {
         self::$permission_cache[$user->getId()] = array();
     }
     if (!array_key_exists($system_permission, self::$permission_cache[$user->getId()])) {
         self::$permission_cache[$user->getId()][$system_permission] = !is_null($permission);
     }
     if (!is_null($permission)) {
         return true;
     }
     return false;
 }
/**
 * Render pagination block
 * 
 * Parameters:
 * 
 * - page - current_page
 * - total_pages - total pages
 * - route - route for URL assembly
 *
 * @param array $params
 * @param Smarty $smarty
 * @return string
 */
function smarty_function_mobile_access_paginator($params, &$smarty)
{
    $url_params = '';
    if (is_foreachable($params)) {
        foreach ($params as $k => $v) {
            if (strpos($k, 'url_param_') !== false && $v) {
                $url_params .= '&amp;' . substr($k, 10) . '=' . $v;
            }
            // if
        }
        // foreach
    }
    // if
    $paginator = array_var($params, 'paginator', new Pager());
    $paginator_url = array_var($params, 'url', ROOT_URL);
    $paginator_anchor = array_var($params, 'anchor', '');
    $smarty->assign(array("_mobile_access_paginator_url" => $paginator_url, "_mobile_access_paginator" => $paginator, '_mobile_access_paginator_anchor' => $paginator_anchor, "_mobile_access_paginator_url_params" => $url_params));
    $paginator_url = strpos($paginator_url, '?') === false ? $paginator_url . '?' : $paginator_url . '&';
    if (!$paginator->isFirst()) {
        $smarty->assign('_mobile_access_paginator_prev_url', $paginator_url . 'page=' . ($paginator->getCurrentPage() - 1) . $url_params . $paginator_anchor);
    }
    // if
    if (!$paginator->isLast()) {
        $smarty->assign('_mobile_access_paginator_next_url', $paginator_url . 'page=' . ($paginator->getCurrentPage() + 1) . $url_params . $paginator_anchor);
    }
    // if
    return $smarty->fetch(get_template_path('_paginator', null, MOBILE_ACCESS_MODULE));
}
 /**
  * authenticate
  *
  * @param string $name
  * @param string $password
  * @return User of false
  */
 function authenticate($login_data)
 {
     $username = array_var($login_data, 'username');
     $password = array_var($login_data, 'password');
     if (trim($username == '')) {
         throw new Error('username value missing');
     }
     // if
     if (trim($password) == '') {
         throw new Error('password value missing');
     }
     // if
     $user = Users::getByUsername($username, owner_company());
     if (!$user instanceof User) {
         throw new Error('invalid login data');
     }
     // if
     if (!$user->isValidPassword($password)) {
         throw new Error('invalid login data');
     }
     // if
     //if (!$user->isDisabled()) {
     //  throw new Error('account disabled');
     //} // if
     return $user;
 }
	function addToSharingTable() {
		parent::addToSharingTable(); //  Default processing
		$oid = $this->getId() ;
		if ( $member = $this->getSelfMember() ) {
			$mid = $member->getId();
			$sql = "
				SELECT distinct(permission_group_id) as gid
			 	FROM ".TABLE_PREFIX."contact_member_permissions 
			 	WHERE member_id = $mid 
			";
			$rows = DB::executeAll($sql);
			if (is_array($rows)) {
				foreach ($rows as $row ) {
					$values = array();
					if ($gid = array_var($row, 'gid')) {					
						$values[] = "($oid, $gid)";
					}
					if (count($values) > 0) {
						$values_str = implode(",", $values);
						DB::execute("INSERT INTO ".TABLE_PREFIX."sharing_table (object_id, group_id) VALUES $values_str ON DUPLICATE KEY UPDATE object_id=object_id");
					}
				}
			}
		}
	}
/**
 * Render object subscribers
 *
 * @param array $params
 * @param Smarty $smarty
 * @return string
 */
function smarty_function_object_subscriptions($params, &$smarty)
{
    $object = array_var($params, 'object');
    if (!instance_of($object, 'ProjectObject')) {
        return new InvalidParamError('object', $object, '$object is expected to be an instance of ProjectObject class', true);
    }
    // if
    js_assign('max_subscribers_count', MAX_SUBSCRIBERS_COUNT);
    require_once SYSTEM_MODULE_PATH . '/helpers/function.user_link.php';
    $subscribers = $object->getSubscribers();
    if (count($subscribers) > MAX_SUBSCRIBERS_COUNT) {
        $smarty->assign(array('_object_subscriptions_list_subscribers' => false, '_object_subscriptions_object' => $object, '_object_subscriptions_subscribers_count' => count($subscribers), '_object_subscription_brief' => array_var($params, 'brief', false), '_object_subscriptions_popup_url' => assemble_url('object_subscribers_widget', array('object_id' => $object->getId()))));
    } else {
        $links = null;
        if (is_foreachable($subscribers)) {
            $links = array();
            foreach ($subscribers as $subscriber) {
                $links[] = smarty_function_user_link(array('user' => $subscriber), $smarty);
            }
            // foreach
        }
        // if
        $smarty->assign(array('_object_subscriptions_list_subscribers' => true, '_object_subscriptions' => $subscribers, '_object_subscriptions_object' => $object, '_object_subscription_links' => $links, '_object_subscription_brief' => array_var($params, 'brief', false), '_object_subscriptions_popup_url' => assemble_url('object_subscribers_widget', array('object_id' => $object->getId()))));
    }
    // if
    return $smarty->fetch(get_template_path('_object_subscriptions', 'subscriptions', RESOURCES_MODULE));
}
/**
 * Render select_default_assignment_filter control
 * 
 * Parameters:
 * 
 * - user - User - User using the page
 * - value - integer - ID of selected filter
 * - optional - boolean - Value is optional?
 *
 * @param array $params
 * @param Smarty $smarty
 * @return string
 */
function smarty_function_select_default_assignment_filter($params, &$smarty)
{
    $user = array_var($params, 'user', null, true);
    $value = array_var($params, 'value', null, true);
    $optional = array_var($params, 'optional', true, true);
    $default_filter_id = (int) ConfigOptions::getValue('default_assignments_filter');
    $default_filter = $default_filter_id ? AssignmentFilters::findById($default_filter_id) : null;
    $options = array();
    if (instance_of($default_filter, 'AssignmentFilter') && $optional) {
        $options[] = option_tag(lang('-- System Default (:filter) --', array('filter' => $default_filter->getName())), '');
    }
    // if
    $grouped_filters = AssignmentFilters::findGrouped($user, true);
    if (is_foreachable($grouped_filters)) {
        foreach ($grouped_filters as $group_name => $filters) {
            $group_options = array();
            foreach ($filters as $filter) {
                $group_options[] = option_tag($filter->getName(), $filter->getId(), array('selected' => $value == $filter->getId()));
            }
            // foreach
            if (count($options) > 0) {
                $options[] = option_tag('', '');
            }
            // if
            $options[] = option_group_tag($group_name, $group_options);
        }
        // foreach
    }
    // if
    return select_box($options, $params);
}
 /**
  * Show and process config category form
  *
  * @param void
  * @return null
  */
 function update_category()
 {
     $category = ConfigCategories::findById(get_id());
     if (!$category instanceof ConfigCategory) {
         flash_error(lang('config category dnx'));
         $this->redirectToReferer(get_url('administration'));
     }
     // if
     if ($category->isEmpty()) {
         flash_error(lang('config category is empty'));
         $this->redirectToReferer(get_url('administration'));
     }
     // if
     $options = $category->getOptions(false);
     $categories = ConfigCategories::getAll(false);
     tpl_assign('category', $category);
     tpl_assign('options', $options);
     tpl_assign('config_categories', $categories);
     $submitted_values = array_var($_POST, 'options');
     if (is_array($submitted_values)) {
         foreach ($options as $option) {
             $new_value = array_var($submitted_values, $option->getName());
             if (is_null($new_value) || $new_value == $option->getValue()) {
                 continue;
             }
             $option->setValue($new_value);
             $option->save();
         }
         // foreach
         flash_success(lang('success update config category', $category->getDisplayName()));
         $this->redirectTo('administration', 'configuration');
     }
     // if
     $this->setSidebar(get_template_path('update_category_sidebar', 'config'));
 }
Beispiel #29
0
/**
 * Add single page action
 * 
 * You can use set of two params where first param is title and second one
 * is URL (the default set) and you can use array of actions as first
 * parram mapped like $title => $url
 *
 * @access public
 * @param string $title
 * @param string $url
 * @return PageAction
 */
function add_page_action()
{
    $args = func_get_args();
    if (!is_array($args) || !count($args)) {
        return;
    }
    // Array of data as first param mapped like $title => $url
    if (is_array(array_var($args, 0))) {
        foreach (array_var($args, 0) as $title => $url) {
            if (!empty($title) && !empty($url)) {
                PageActions::instance()->addAction(new PageAction($title, $url));
            }
            // if
        }
        // foreach
        // Two string params, title and URL
    } else {
        $title = array_var($args, 0);
        $url = array_var($args, 1);
        if (!empty($title) && !empty($url)) {
            PageActions::instance()->addAction(new PageAction($title, $url));
        }
        // if
    }
    // if
}
/**
 * Show object visibility if it's private
 *
 * @param array $params
 * @param Smarty $smarty
 * @return string
 */
function smarty_function_object_visibility($params, &$smarty)
{
    static $ids = array();
    $object = array_var($params, 'object');
    if (!instance_of($object, 'ProjectObject')) {
        return new InvalidParamError('object', $object, '$object is not valid instance of ProjectObject class', true);
    }
    // if
    if ($object->getVisibility() > VISIBILITY_PRIVATE) {
        return '';
    }
    // if
    $user = array_var($params, 'user');
    if (!instance_of($user, 'User')) {
        return new InvalidParamError('user', $user, '$user is expected to be an instance of User class', true);
    }
    // if
    if (!$user->canSeePrivate()) {
        return '';
    }
    // if
    $id = array_var($params, 'id');
    if (empty($id)) {
        do {
            $id = 'object_visibility_' . make_string(40);
        } while (in_array($id, $ids));
    }
    // if
    $ids[] = $id;
    return open_html_tag('a', array('href' => assemble_url('project_object_visibility', array('project_id' => $object->getProjectId(), 'object_id' => $object->getId())), 'title' => lang('Private :type', array('type' => Inflector::humanize($object->getType()))), 'class' => 'object_visibility', 'id' => $id)) . '<img src="' . get_image_url('private.gif') . '" alt="" /></a><script type="text/javascript">App.widgets.ObjectVisibility.init("' . $id . '");</script>';
}