function getBillingCategory()
 {
     if (is_null($this->billing_category)) {
         $this->billing_category = BillingCategories::findById($this->getBillingId());
     }
     // if
     return $this->billing_category;
 }
Example #2
0
 static function updateBillingValues()
 {
     $timeslot_rows = DB::executeAll("SELECT * FROM " . TABLE_PREFIX . "timeslots WHERE `end_time` > 0 AND billing_id = 0 AND is_fixed_billing = 0");
     $users = Contacts::getAllUsers();
     $usArray = array();
     foreach ($users as $u) {
         $usArray[$u->getId()] = $u;
     }
     $count = 0;
     $categories_cache = array();
     foreach ($timeslot_rows as $ts_row) {
         if ($ts_row['start_time'] == EMPTY_DATETIME) {
             $ts_row['minutes'] = 0;
         } else {
             $startTime = DateTimeValueLib::makeFromString($ts_row['start_time']);
             if ($ts_row['start_time'] == EMPTY_DATETIME) {
                 $endTime = $ts_row['is_paused'] ? DateTimeValueLib::makeFromString($ts_row['paused_on']) : DateTimeValueLib::now();
             } else {
                 $endTime = DateTimeValueLib::makeFromString($ts_row['end_time']);
             }
             $timeDiff = DateTimeValueLib::get_time_difference($startTime->getTimestamp(), $endTime->getTimestamp(), $ts_row['subtract']);
             $ts_row['minutes'] = $timeDiff['days'] * 1440 + $timeDiff['hours'] * 60 + $timeDiff['minutes'];
         }
         $user = $usArray[$ts_row['contact_id']];
         if ($user instanceof Contact) {
             $billing_category_id = $user->getDefaultBillingId();
             if ($billing_category_id > 0) {
                 $hours = $ts_row['minutes'] / 60;
                 $billing_category = array_var($categories_cache, $billing_category_id);
                 if (!$billing_category instanceof BillingCategory) {
                     $billing_category = BillingCategories::findById($billing_category_id);
                     $categories_cache[$billing_category_id] = $billing_category;
                 }
                 if ($billing_category instanceof BillingCategory) {
                     $hourly_billing = $billing_category->getDefaultValue();
                     DB::execute("UPDATE " . TABLE_PREFIX . "timeslots SET billing_id='{$billing_category_id}', hourly_billing='{$hourly_billing}', \r\n\t\t\t\t\t\t\tfixed_billing='" . round($hourly_billing * $hours, 2) . "', is_fixed_billing=0 \r\n\t\t\t\t\t\t\tWHERE object_id=" . $ts_row['object_id']);
                     $count++;
                 }
             }
         } else {
             DB::execute("UPDATE " . TABLE_PREFIX . "timeslots SET is_fixed_billing=1 WHERE object_id=" . $ts_row['object_id']);
         }
     }
     return $count;
 }
Example #3
0
 /**
  * Returns an array with a list of values and information about where they were obtained from
  *
  * @param array $billing_category_ids
  */
 function getBillingAmounts($billing_categories = null)
 {
     if (!$billing_categories) {
         $billing_categories = BillingCategories::findAll();
     }
     if ($billing_categories && count($billing_categories) > 0) {
         $result = array();
         $billing_category_ids = array();
         foreach ($billing_categories as $category) {
             $billing_category_ids[] = $category->getId();
         }
         $wsBillingCategories = WorkspaceBillings::findAll(array('conditions' => 'project_id = ' . $this->getId() . ' and billing_id in (' . implode(',', $billing_category_ids) . ')'));
         if ($wsBillingCategories) {
             foreach ($wsBillingCategories as $wsCategory) {
                 for ($i = 0; $i < count($billing_categories); $i++) {
                     if ($billing_categories[$i]->getId() == $wsCategory->getBillingId()) {
                         $result[] = array('category' => $billing_categories[$i], 'value' => $wsCategory->getValue(), 'origin' => $this->getId());
                         array_splice($billing_categories, $i, 1);
                         array_splice($billing_category_ids, $i, 1);
                         break;
                     }
                 }
             }
         }
         if (count($billing_categories) > 0) {
             if ($this->getParentWorkspace() instanceof Project) {
                 $resultToConcat = $this->getParentWorkspace()->getBillingAmounts($billing_categories);
                 foreach ($resultToConcat as $resultValue) {
                     $result[] = array('category' => $resultValue['category'], 'value' => $resultValue['value'], 'origin' => $resultValue['origin'] == 'default' ? 'default' : 'inherited');
                 }
             } else {
                 foreach ($billing_categories as $category) {
                     $result[] = array('category' => $category, 'value' => $category->getDefaultValue(), 'origin' => 'default');
                 }
             }
         }
         return $result;
     } else {
         return null;
     }
 }
Example #4
0
 /**
  * This function sets the selected billing values for all timeslots which lack any type of billing values (value set to 0). 
  * This function is used when users start to use billing in the system.
  * 
  * @return unknown_type
  */
 static function updateBillingValues()
 {
     $timeslots = Timeslots::findAll(array('conditions' => '`end_time` > 0 AND billing_id = 0 AND is_fixed_billing = 0', 'join' => array('table' => Objects::instance()->getTableName(true), 'jt_field' => 'id', 'e_field' => 'rel_object_id')));
     $users = Contacts::getAllUsers();
     $usArray = array();
     foreach ($users as $u) {
         $usArray[$u->getId()] = $u;
     }
     $pbidCache = array();
     $count = 0;
     $categories_cache = array();
     foreach ($timeslots as $ts) {
         /* @var $ts Timeslot */
         $user = $usArray[$ts->getContactId()];
         if ($user instanceof Contact) {
             $billing_category_id = $user->getDefaultBillingId();
             if ($billing_category_id > 0) {
                 $hours = $ts->getMinutes() / 60;
                 $billing_category = array_var($categories_cache, $billing_category_id);
                 if (!$billing_category instanceof BillingCategory) {
                     $billing_category = BillingCategories::findById($billing_category_id);
                     $categories_cache[$billing_category_id] = $billing_category;
                 }
                 if ($billing_category instanceof BillingCategory) {
                     $hourly_billing = $billing_category->getDefaultValue();
                     $ts->setBillingId($billing_category_id);
                     $ts->setHourlyBilling($hourly_billing);
                     $ts->setFixedBilling(round($hourly_billing * $hours, 2));
                     $ts->setIsFixedBilling(false);
                     $ts->save();
                     $count++;
                 }
             }
         } else {
             $ts->setIsFixedBilling(true);
             $ts->save();
         }
     }
     return $count;
 }
 /**
  * Edit timeslot
  *
  * @param void
  * @return null
  */
 function edit()
 {
     if (!can_manage_time(logged_user(), true)) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     $this->setTemplate('add_timeslot');
     $timeslot = Timeslots::findById(get_id());
     if (!$timeslot instanceof Timeslot) {
         flash_error(lang('timeslot dnx'));
         ajx_current("empty");
         return;
     }
     // if
     $object = $timeslot->getObject();
     if (!$object instanceof ProjectDataObject) {
         flash_error(lang('object dnx'));
         ajx_current("empty");
         return;
     }
     // if
     if (!$object->canAddTimeslot(logged_user())) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     // if
     if (!$timeslot->canEdit(logged_user())) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     // if
     $timeslot_data = array_var($_POST, 'timeslot');
     if (!is_array($timeslot_data)) {
         $timeslot_data = array('description' => $timeslot->getDescription(), 'start_time' => $timeslot->getStartTime(), 'end_time' => $timeslot->getEndTime(), 'is_fixed_billing' => $timeslot->getIsFixedBilling(), 'hourly_billing' => $timeslot->getHourlyBilling(), 'fixed_billing' => $timeslot->getFixedBilling());
         // array
     }
     // if
     tpl_assign('timeslot_form_object', $object);
     tpl_assign('timeslot', $timeslot);
     tpl_assign('timeslot_data', $timeslot_data);
     tpl_assign('show_billing', BillingCategories::count() > 0);
     if (is_array(array_var($_POST, 'timeslot'))) {
         try {
             $timeslot->setDescription(array_var($timeslot_data, 'description'));
             $st = getDateValue(array_var($timeslot_data, 'start_value'), DateTimeValueLib::now());
             $st->setHour(array_var($timeslot_data, 'start_hour'));
             $st->setMinute(array_var($timeslot_data, 'start_minute'));
             $et = getDateValue(array_var($timeslot_data, 'end_value'), DateTimeValueLib::now());
             $et->setHour(array_var($timeslot_data, 'end_hour'));
             $et->setMinute(array_var($timeslot_data, 'end_minute'));
             $st = new DateTimeValue($st->getTimestamp() - logged_user()->getTimezone() * 3600);
             $et = new DateTimeValue($et->getTimestamp() - logged_user()->getTimezone() * 3600);
             $timeslot->setStartTime($st);
             $timeslot->setEndTime($et);
             if ($timeslot->getStartTime() > $timeslot->getEndTime()) {
                 flash_error(lang('error start time after end time'));
                 ajx_current("empty");
                 return;
             }
             $seconds = array_var($timeslot_data, 'subtract_seconds', 0);
             $minutes = array_var($timeslot_data, 'subtract_minutes', 0);
             $hours = array_var($timeslot_data, 'subtract_hours', 0);
             $subtract = $seconds + 60 * $minutes + 3600 * $hours;
             if ($subtract < 0) {
                 flash_error(lang('pause time cannot be negative'));
                 ajx_current("empty");
                 return;
             }
             $testEndTime = new DateTimeValue($timeslot->getEndTime()->getTimestamp());
             $testEndTime->add('s', -$subtract);
             if ($timeslot->getStartTime() > $testEndTime) {
                 flash_error(lang('pause time cannot exceed timeslot time'));
                 ajx_current("empty");
                 return;
             }
             $timeslot->setSubtract($subtract);
             /* Billing */
             $timeslot->setIsFixedBilling(array_var($timeslot_data, 'is_fixed_billing', false));
             $timeslot->setHourlyBilling(array_var($timeslot_data, 'hourly_billing', 0));
             if ($timeslot->getIsFixedBilling()) {
                 $timeslot->setFixedBilling(array_var($timeslot_data, 'fixed_billing', 0));
             } else {
                 $timeslot->setFixedBilling($timeslot->getHourlyBilling() * $timeslot->getMinutes() / 60);
             }
             if ($timeslot->getBillingId() == 0 && ($timeslot->getHourlyBilling() > 0 || $timeslot->getFixedBilling() > 0)) {
                 $timeslot->setBillingId($timeslot->getUser()->getDefaultBillingId());
             }
             DB::beginWork();
             $timeslot->save();
             DB::commit();
             flash_success(lang('success edit timeslot'));
             ajx_current("back");
         } catch (Exception $e) {
             DB::rollback();
             flash_error(lang('error edit timeslot'));
             ajx_current("empty");
         }
         // try
     }
 }
 /**
  * Add project
  *
  * @param void
  * @return null
  */
 function add()
 {
     if (logged_user()->isGuest()) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     $this->setTemplate('add_project');
     if (!Project::canAdd(logged_user())) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     // if
     $project = new Project();
     $project_data = array_var($_POST, 'project');
     $projects = logged_user()->getActiveProjects();
     if (active_project() instanceof Project) {
         $billing_amounts = active_project()->getBillingAmounts();
     } else {
         $billing_amounts = BillingCategories::getDefaultBillingAmounts();
     }
     tpl_assign('project', $project);
     tpl_assign('projects', $projects);
     tpl_assign('project_data', $project_data);
     tpl_assign('billing_amounts', $billing_amounts);
     // Submited...
     if (is_array($project_data)) {
         $project->setFromAttributes($project_data);
         try {
             DB::beginWork();
             $project->save();
             //Save to get the id, then update the project path info
             if (array_var($project_data, 'parent_id') != $project->getParentId()) {
                 $parent = Projects::findById(array_var($project_data, 'parent_id'));
                 if ($parent) {
                     if (!$project->canSetAsParentWorkspace($parent)) {
                         flash_error(lang('error cannot set workspace as parent', $parent->getName()));
                         ajx_current("empty");
                         return;
                     }
                 }
                 $project->setParentWorkspace($parent);
             }
             $project->save();
             /* Billing */
             $billings = array_var($project_data, 'billing', null);
             if ($billings) {
                 foreach ($billings as $billing_id => $billing) {
                     if ($billing['update'] && $billing['value'] && $billing['value'] != 0) {
                         $wb = new WorkspaceBilling();
                         $wb->setProjectId($project->getId());
                         $wb->setBillingId($billing_id);
                         $value = $billing['value'];
                         if (strpos($value, ',') && !strpos($value, '.')) {
                             $value = str_replace(',', '.', $value);
                         }
                         $wb->setValue($value);
                         $wb->save();
                     }
                 }
             }
             /* Project contacts */
             if (can_manage_contacts(logged_user())) {
                 $contacts = array_var($project_data, 'contacts', null);
                 if ($contacts) {
                     foreach ($contacts as $contact_data) {
                         $contact = Contacts::findById($contact_data['contact_id']);
                         if ($contact instanceof Contact) {
                             $pc = new ProjectContact();
                             $pc->setProjectId($project->getId());
                             $pc->setContactId($contact_data['contact_id']);
                             $pc->setRole($contact_data['role']);
                             $pc->save();
                         }
                     }
                 }
             }
             /* <permissions> */
             $permissions = null;
             $permissionsString = array_var($_POST, 'permissions');
             if ($permissionsString && $permissionsString != '') {
                 $permissions = json_decode($permissionsString);
             }
             if (is_array($permissions) && count($permissions) > 0) {
                 //Add new permissions
                 //TODO - Make batch update of these permissions
                 foreach ($permissions as $perm) {
                     if (ProjectUser::hasAnyPermissions($perm->pr, $perm->pc)) {
                         $relation = new ProjectUser();
                         $relation->setProjectId($project->getId());
                         $relation->setUserId($perm->wsid);
                         $relation->setCheckboxPermissions($perm->pc, $relation->getUserOrGroup()->isGuest() ? false : true);
                         $relation->setRadioPermissions($perm->pr, $relation->getUserOrGroup()->isGuest() ? false : true);
                         $relation->save();
                     }
                     //endif
                     //else if the user has no permissions at all, he is not a project_user. ProjectUser is not created
                 }
                 //end foreach
             }
             // if
             /* </permissions> */
             $object_controller = new ObjectController();
             $object_controller->add_custom_properties($project);
             ApplicationLogs::createLog($project, null, ApplicationLogs::ACTION_ADD, false, true);
             DB::commit();
             if (logged_user()->isProjectUser($project)) {
                 evt_add("workspace added", array("id" => $project->getId(), "name" => $project->getName(), "color" => $project->getColor(), "parent" => $project->getParentId()));
             }
             flash_success(lang('success add project', $project->getName()));
             ajx_current("back");
             return;
         } catch (Exception $e) {
             DB::rollback();
             flash_error($e->getMessage());
             ajx_current("empty");
         }
         // try
     }
     // if
 }
 function total_task_times_p()
 {
     if (array_var($_GET, 'ws') !== null) {
         $report_data = array_var($_SESSION, 'total_task_times_report_data', array());
         $report_data['project_id'] = array_var($_GET, 'ws');
         $_SESSION['total_task_times_report_data'] = $report_data;
         $this->redirectTo('reporting', 'total_task_times_p', array('type' => array_var($_GET, 'type', '')));
     }
     $comp = logged_user()->getCompany();
     $users = $comp instanceof Company ? $comp->getUsers() : owner_company()->getUsers();
     $workspaces = logged_user()->getActiveProjects();
     tpl_assign('type', array_var($_GET, 'type'));
     tpl_assign('workspaces', $workspaces);
     tpl_assign('users', $users);
     tpl_assign('has_billing', BillingCategories::count() > 0);
 }
 function total_task_times_p()
 {
     if (array_var($_GET, 'ws') !== null) {
         $report_data = array_var($_SESSION, 'total_task_times_report_data', array());
         if (array_var($_GET, 'type')) {
             $report_data['timeslot_type'] = array_var($_GET, 'type');
         }
         $_SESSION['total_task_times_report_data'] = $report_data;
         $this->redirectTo('reporting', 'total_task_times_p');
     }
     $users = Contacts::getAllUsers();
     tpl_assign('users', $users);
     tpl_assign('has_billing', BillingCategories::count() > 0);
 }
 /**
  * This function will return paginated result. Result is an array where first element is 
  * array of returned object and second populated pagination object that can be used for 
  * obtaining and rendering pagination data using various helpers.
  * 
  * Items and pagination array vars are indexed with 0 for items and 1 for pagination
  * because you can't use associative indexing with list() construct
  *
  * @access public
  * @param array $arguments Query argumens (@see find()) Limit and offset are ignored!
  * @param integer $items_per_page Number of items per page
  * @param integer $current_page Current page number
  * @return array
  */
 function paginate($arguments = null, $items_per_page = 10, $current_page = 1)
 {
     if (isset($this) && instance_of($this, 'BillingCategories')) {
         return parent::paginate($arguments, $items_per_page, $current_page);
     } else {
         return BillingCategories::instance()->paginate($arguments, $items_per_page, $current_page);
         //$instance =& BillingCategories::instance();
         //return $instance->paginate($arguments, $items_per_page, $current_page);
     }
     // if
 }
	/**
	 * Empty implementation of static method.
	 *
	 * Add tag permissions are done through ProjectDataObject::canBillingCategory() method. This
	 * will return BillingCategory permissions for specified object
	 *
	 * @param User $user
	 * @param Project $project
	 * @return boolean
	 */
	function canAdd(Contact $user, Project $project) {		
		return can_add($user,$project,get_class(BillingCategories::instance()));
	} // canAdd
 /**
 * Return manager instance
 *
 * @access protected
 * @param void
 * @return BillingCategories 
 */
 function manager() {
   if(!($this->manager instanceof BillingCategories)) $this->manager = BillingCategories::instance();
   return $this->manager;
 } // manager
 /**
  * Edit logged user profile. 
  * Called with different POST format from "administration/users/edit user profile " and from "profile/edit my profile" 
  *
  * @access public
  * @param void
  * @return null
  */
 function edit_profile()
 {
     $user = Users::findById(get_id());
     if (!$user instanceof User) {
         flash_error(lang('user dnx'));
         ajx_current("empty");
         return;
     }
     // if
     $company = $user->getCompany();
     if (!$company instanceof Company) {
         flash_error(lang('company dnx'));
         ajx_current("empty");
         return;
     }
     // if
     if (!$user->canUpdateProfile(logged_user())) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     // if
     $redirect_to = array_var($_GET, 'redirect_to');
     if (trim($redirect_to) == '' || !is_valid_url($redirect_to)) {
         $redirect_to = $user->getCardUrl();
     }
     // if
     tpl_assign('redirect_to', null);
     $user_data = array_var($_POST, 'user');
     if (!is_array($user_data)) {
         $user_data = array('username' => $user->getUsername(), 'email' => $user->getEmail(), 'display_name' => $user->getDisplayName(), 'title' => $user->getTitle(), 'timezone' => $user->getTimezone(), 'auto_assign' => $user->getAutoAssign(), 'company_id' => $user->getCompanyId(), 'is_admin' => $user->isAdministrator(), 'type' => $user->getType());
         // array
     }
     // if
     tpl_assign('user', $user);
     tpl_assign('company', $company);
     tpl_assign('user_data', $user_data);
     tpl_assign('billing_categories', BillingCategories::findAll());
     if (is_array(array_var($_POST, 'user'))) {
         if (array_var($user_data, 'company_id') && !Companies::findById(array_var($user_data, 'company_id')) instanceof Company) {
             ajx_current("empty");
             flash_error(lang("company dnx"));
             return;
         }
         try {
             DB::beginWork();
             $user->setDisplayName(array_var($user_data, 'display_name'));
             $user->setEmail(array_var($user_data, 'email'));
             $user->setType(array_var($user_data, 'type'));
             $user->setTimezone(array_var($user_data, 'timezone'));
             $user->setTitle(array_var($user_data, 'title'));
             $user->setUpdatedOn(DateTimeValueLib::now());
             if (logged_user()->isAdministrator()) {
                 if ($user->getId() != 1) {
                     // System admin cannot change it's company
                     $user->setCompanyId(array_var($user_data, 'company_id'));
                 }
                 $user->setDefaultBillingId(array_var($user_data, 'default_billing_id'));
                 $user->setUsername(array_var($user_data, 'username'));
                 $project = Projects::findById(array_var($user_data, 'personal_project_id'));
                 if ($project instanceof Project && $user->getPersonalProjectId() != $project->getId()) {
                     $user->setPersonalProjectId($project->getId());
                     $project_user = ProjectUsers::findById(array('project_id' => $project->getId(), 'user_id' => $user->getId()));
                     if (!$project_user) {
                         $project_user = new ProjectUser();
                         $project_user->setUserId($user->getId());
                         $project_user->setProjectId($project->getId());
                     }
                     $project_user->setAllPermissions(true);
                     $project_user->save();
                 }
             }
             $user->save();
             $autotimezone = array_var($user_data, 'autodetect_time_zone', null);
             if ($autotimezone !== null) {
                 set_user_config_option('autodetect_time_zone', $autotimezone, $user->getId());
             }
             $object_controller = new ObjectController();
             $object_controller->add_custom_properties($user);
             if ($user->getId() != 1) {
                 //System admin cannot change its own admin status
                 if ($user->getType() == 'admin') {
                     if ($user->getCompanyId() != owner_company()->getId()) {
                         // external users can't be admins => set as Normal
                         $user->setType('normal');
                         $user->setAsAdministrator(false);
                     } else {
                         $user->setAsAdministrator(true);
                     }
                 } else {
                     $user->setAsAdministrator(false);
                 }
             }
             DB::commit();
             flash_success(lang('success update profile'));
             ajx_current("back");
             ajx_add("overview-panel", "reload");
         } catch (Exception $e) {
             DB::rollback();
             ajx_current("empty");
             flash_error($e->getMessage());
         }
         // try
     }
     // if
 }
 /**
  * Show dashboard index page
  *
  * @param void
  * @return null
  */
 function index()
 {
     $this->setHelp('dashboard');
     $tag = array_var($_GET, 'active_tag');
     $logged_user = logged_user();
     if (active_project() instanceof Project) {
         $wscsv = active_project()->getAllSubWorkspacesQuery(true);
     } else {
         $wscsv = null;
     }
     $activity_log = null;
     $include_private = $logged_user->isMemberOfOwnerCompany();
     $include_silent = $logged_user->isAdministrator();
     $activity_log = ApplicationLogs::getOverallLogs($include_private, $include_silent, $wscsv, config_option('dashboard_logs_count', 15));
     if (user_config_option('show charts widget') && module_enabled('reporting')) {
         $charts = ProjectCharts::getChartsAtProject(active_project(), active_tag());
         tpl_assign('charts', $charts);
         if (BillingCategories::count() > 0 && active_project() instanceof Project) {
             tpl_assign('billing_chart_data', active_project()->getBillingTotalByUsers(logged_user()));
         }
     }
     if (user_config_option('show messages widget') && module_enabled('notes')) {
         list($messages, $pagination) = ProjectMessages::getMessages(active_tag(), active_project(), 0, 10, '`updated_on`', 'DESC', false);
         tpl_assign('messages', $messages);
     }
     if (user_config_option('show comments widget')) {
         $comments = Comments::getSubscriberComments(active_project(), $tag);
         tpl_assign('comments', $comments);
     }
     if (user_config_option('show documents widget') && module_enabled('documents')) {
         list($documents, $pagination) = ProjectFiles::getProjectFiles(active_project(), null, false, ProjectFiles::ORDER_BY_MODIFYTIME, 'DESC', 1, 10, false, active_tag(), null);
         tpl_assign('documents', $documents);
     }
     if (user_config_option('show emails widget') && module_enabled('email')) {
         $activeWs = active_project();
         list($unread_emails, $pagination) = MailContents::getEmails($tag, null, 'received', 'unread', '', $activeWs, 0, 10);
         if ($activeWs && user_config_option('always show unread mail in dashboard')) {
             // add unread unclassified emails
             list($all_unread, $pagination) = MailContents::getEmails($tag, null, 'received', 'unread', 'unclassified', null, 0, 10);
             $unread_emails = array_merge($unread_emails, $all_unread);
         }
         tpl_assign('unread_emails', $unread_emails);
     }
     //Tasks widgets
     $show_pending = user_config_option('show pending tasks widget') && module_enabled('tasks');
     $show_in_progress = user_config_option('show tasks in progress widget') && module_enabled('tasks');
     $show_late = user_config_option('show late tasks and milestones widget') && module_enabled('tasks');
     if ($show_pending || $show_in_progress || $show_late) {
         $assigned_to = explode(':', user_config_option('pending tasks widget assigned to filter'));
         $to_company = array_var($assigned_to, 0, 0);
         $to_user = array_var($assigned_to, 1, 0);
         tpl_assign('assigned_to_user_filter', $to_user);
         tpl_assign('assigned_to_company_filter', $to_company);
     }
     if ($show_pending) {
         $tasks = ProjectTasks::getProjectTasks(active_project(), ProjectTasks::ORDER_BY_DUEDATE, 'ASC', null, null, $tag, $to_company, $to_user, null, true, 'all', false, false, false, 10);
         tpl_assign('dashtasks', $tasks);
     }
     if ($show_in_progress) {
         $tasks_in_progress = ProjectTasks::getOpenTimeslotTasks(logged_user(), logged_user(), active_project(), $tag, $to_company, $to_user);
         tpl_assign('tasks_in_progress', $tasks_in_progress);
     }
     if ($show_late) {
         tpl_assign('today_milestones', $logged_user->getTodayMilestones(active_project(), $tag, 10));
         tpl_assign('late_milestones', $logged_user->getLateMilestones(active_project(), $tag, 10));
         tpl_assign('today_tasks', ProjectTasks::getDayTasksByUser(DateTimeValueLib::now(), $logged_user, active_project(), $tag, $to_company, $to_user, 10));
         tpl_assign('late_tasks', ProjectTasks::getLateTasksByUser($logged_user, active_project(), $tag, $to_company, $to_user, 10));
     }
     tpl_assign('activity_log', $activity_log);
     $usu = logged_user();
     $conditions = array("conditions" => array("`state` >= 200 AND (`state`%2 = 0) AND `trashed_by_id`=0 AND `created_by_id` =" . $usu->getId()));
     $outbox_mails = MailContents::findAll($conditions);
     if ($outbox_mails != null) {
         if (count($outbox_mails) == 1) {
             flash_error(lang('outbox mail not sent', 1));
         } else {
             if (count($outbox_mails) > 1) {
                 flash_error(lang('outbox mails not sent', count($outbox_mails)));
             }
         }
     }
     ajx_set_no_toolbar(true);
 }
 /**
  * Add user
  *
  * @access public
  * @param void
  * @return null
  */
 function add()
 {
     if (logged_user()->isGuest()) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     $max_users = config_option('max_users');
     if ($max_users && Users::count() >= $max_users) {
         flash_error(lang('maximum number of users reached error'));
         ajx_current("empty");
         return;
     }
     $this->setTemplate('add_user');
     $company = Companies::findById(get_id('company_id'));
     if (!$company instanceof Company) {
         $company = owner_company();
     }
     // if
     if (!User::canAdd(logged_user(), $company)) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     // if
     $user = new User();
     $user_data = array_var($_POST, 'user');
     if (!is_array($user_data)) {
         //if it is a new user
         $contact_id = get_id('contact_id');
         $contact = Contacts::findById($contact_id);
         if ($contact instanceof Contact) {
             //if it will be created from a contact
             $user_data = array('username' => $this->generateUserNameFromContact($contact), 'display_name' => $contact->getFirstname() . $contact->getLastname(), 'email' => $contact->getEmail(), 'contact_id' => $contact->getId(), 'password_generator' => 'random', 'company_id' => $company->getId(), 'timezone' => $contact->getTimezone(), 'create_contact' => false, 'type' => 'normal', 'can_manage_time' => true);
             // array
         } else {
             // if it is new, and created from admin interface
             $user_data = array('password_generator' => 'random', 'company_id' => $company->getId(), 'timezone' => $company->getTimezone(), 'create_contact' => true, 'send_email_notification' => true, 'type' => 'normal', 'can_manage_time' => true);
             // array
         }
     }
     // if
     $permissions = ProjectUsers::getNameTextArray();
     tpl_assign('user', $user);
     tpl_assign('company', $company);
     tpl_assign('permissions', $permissions);
     tpl_assign('user_data', $user_data);
     tpl_assign('billing_categories', BillingCategories::findAll());
     if (is_array(array_var($_POST, 'user'))) {
         if (!array_var($user_data, 'createPersonalProject')) {
             $user_data['personal_project'] = 0;
         }
         try {
             DB::beginWork();
             $user = $this->createUser($user_data, array_var($_POST, 'permissions'));
             $object_controller = new ObjectController();
             $object_controller->add_custom_properties($user);
             DB::commit();
             flash_success(lang('success add user', $user->getDisplayName()));
             ajx_current("back");
         } catch (Exception $e) {
             DB::rollback();
             ajx_current("empty");
             flash_error($e->getMessage());
         }
         // try
     }
     // if
 }
 function edit_timeslot()
 {
     if (!can_add(logged_user(), active_context(), Timeslots::instance()->getObjectTypeId())) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     ajx_current("empty");
     $timeslot_data = array_var($_POST, 'timeslot');
     $timeslot = Timeslots::findById(array_var($timeslot_data, 'id', 0));
     if (!$timeslot instanceof Timeslot) {
         flash_error(lang('timeslot dnx'));
         return;
     }
     try {
         $hoursToAdd = array_var($timeslot_data, 'hours', 0);
         $minutes = array_var($timeslot_data, 'minutes', 0);
         if (strpos($hoursToAdd, ',') && !strpos($hoursToAdd, '.')) {
             $hoursToAdd = str_replace(',', '.', $hoursToAdd);
         }
         if (strpos($hoursToAdd, ':') && !strpos($hoursToAdd, '.')) {
             $pos = strpos($hoursToAdd, ':') + 1;
             $len = strlen($hoursToAdd) - $pos;
             $minutesToAdd = substr($hoursToAdd, $pos, $len);
             if (!strlen($minutesToAdd) <= 2 || !strlen($minutesToAdd) > 0) {
                 $minutesToAdd = substr($minutesToAdd, 0, 2);
             }
             $mins = $minutesToAdd / 60;
             $hours = substr($hoursToAdd, 0, $pos - 1);
             $hoursToAdd = $hours + $mins;
         }
         if ($minutes) {
             $min = str_replace('.', '', $minutes / 6);
             $hoursToAdd = $hoursToAdd + ("0." . $min);
         }
         if ($hoursToAdd <= 0) {
             flash_error(lang('time has to be greater than 0'));
             return;
         }
         $startTime = getDateValue(array_var($timeslot_data, 'date'));
         $startTime = $startTime->add('h', 8 - logged_user()->getTimezone());
         $endTime = getDateValue(array_var($timeslot_data, 'date'));
         $endTime = $endTime->add('h', 8 - logged_user()->getTimezone() + $hoursToAdd);
         $timeslot_data['start_time'] = $startTime;
         $timeslot_data['end_time'] = $endTime;
         $timeslot_data['name'] = $timeslot_data['description'];
         //Only admins can change timeslot user
         if (array_var($timeslot_data, 'contact_id', false) && !logged_user()->isAdministrator()) {
             $timeslot_data['contact_id'] = $timeslot->getContactId();
         }
         $timeslot->setFromAttributes($timeslot_data);
         $user = Contacts::findById($timeslot_data['contact_id']);
         $billing_category_id = $user->getDefaultBillingId();
         $bc = BillingCategories::findById($billing_category_id);
         if ($bc instanceof BillingCategory) {
             $timeslot->setBillingId($billing_category_id);
             $hourly_billing = $bc->getDefaultValue();
             $timeslot->setHourlyBilling($hourly_billing);
             $timeslot->setFixedBilling($hourly_billing * $hoursToAdd);
             $timeslot->setIsFixedBilling(false);
         }
         DB::beginWork();
         $timeslot->save();
         $member_ids = json_decode(array_var($_POST, 'members', ''));
         if ($member_ids && count($member_ids)) {
             ajx_add("time-panel", "reload");
         } else {
             foreach (active_context() as $dimension) {
                 $names[] = $dimension->getName();
             }
             flash_error(lang('select member to add timeslots', implode(", ", $names)));
             //flash_error(lang('must choose at least one member'));
             DB::rollback();
             return;
         }
         $object_controller = new ObjectController();
         $object_controller->add_to_members($timeslot, $member_ids);
         DB::commit();
         ajx_extra_data(array("timeslot" => $timeslot->getArrayInfo()));
     } catch (Exception $e) {
         DB::rollback();
         flash_error($e->getMessage());
     }
     // try
 }
 /**
  * Edit timeslot
  *
  * @param void
  * @return null
  */
 function edit()
 {
     $this->setTemplate('add_timeslot');
     $timeslot = Timeslots::findById(get_id());
     if (!$timeslot instanceof Timeslot) {
         flash_error(lang('timeslot dnx'));
         ajx_current("empty");
         return;
     }
     $object = $timeslot->getRelObject();
     if (!$object instanceof ContentDataObject) {
         flash_error(lang('object dnx'));
         ajx_current("empty");
         return;
     }
     if (!$object->canAddTimeslot(logged_user())) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     if (!$timeslot->canEdit(logged_user())) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     $timeslot_data = array_var($_POST, 'timeslot');
     if (!is_array($timeslot_data)) {
         $timeslot_data = array('contact_id' => $timeslot->getContactId(), 'description' => $timeslot->getDescription(), 'start_time' => $timeslot->getStartTime(), 'end_time' => $timeslot->getEndTime(), 'is_fixed_billing' => $timeslot->getIsFixedBilling(), 'hourly_billing' => $timeslot->getHourlyBilling(), 'fixed_billing' => $timeslot->getFixedBilling());
     }
     tpl_assign('timeslot_form_object', $object);
     tpl_assign('timeslot', $timeslot);
     tpl_assign('timeslot_data', $timeslot_data);
     tpl_assign('show_billing', BillingCategories::count() > 0);
     if (is_array(array_var($_POST, 'timeslot'))) {
         try {
             $this->percent_complete_delete($timeslot);
             $timeslot->setContactId(array_var($timeslot_data, 'contact_id', logged_user()->getId()));
             $timeslot->setDescription(array_var($timeslot_data, 'description'));
             $st = getDateValue(array_var($timeslot_data, 'start_value'), DateTimeValueLib::now());
             $st->setHour(array_var($timeslot_data, 'start_hour'));
             $st->setMinute(array_var($timeslot_data, 'start_minute'));
             $et = getDateValue(array_var($timeslot_data, 'end_value'), DateTimeValueLib::now());
             $et->setHour(array_var($timeslot_data, 'end_hour'));
             $et->setMinute(array_var($timeslot_data, 'end_minute'));
             $st = new DateTimeValue($st->getTimestamp() - logged_user()->getTimezone() * 3600);
             $et = new DateTimeValue($et->getTimestamp() - logged_user()->getTimezone() * 3600);
             $timeslot->setStartTime($st);
             $timeslot->setEndTime($et);
             if ($timeslot->getStartTime() > $timeslot->getEndTime()) {
                 flash_error(lang('error start time after end time'));
                 ajx_current("empty");
                 return;
             }
             $seconds = array_var($timeslot_data, 'subtract_seconds', 0);
             $minutes = array_var($timeslot_data, 'subtract_minutes', 0);
             $hours = array_var($timeslot_data, 'subtract_hours', 0);
             $subtract = $seconds + 60 * $minutes + 3600 * $hours;
             if ($subtract < 0) {
                 flash_error(lang('pause time cannot be negative'));
                 ajx_current("empty");
                 return;
             }
             $testEndTime = new DateTimeValue($timeslot->getEndTime()->getTimestamp());
             $testEndTime->add('s', -$subtract);
             if ($timeslot->getStartTime() > $testEndTime) {
                 flash_error(lang('pause time cannot exceed timeslot time'));
                 ajx_current("empty");
                 return;
             }
             $timeslot->setSubtract($subtract);
             if ($timeslot->getUser()->getDefaultBillingId()) {
                 $timeslot->setIsFixedBilling(array_var($timeslot_data, 'is_fixed_billing', false));
                 $timeslot->setHourlyBilling(array_var($timeslot_data, 'hourly_billing', 0));
                 if ($timeslot->getIsFixedBilling()) {
                     $timeslot->setFixedBilling(array_var($timeslot_data, 'fixed_billing', 0));
                 } else {
                     $timeslot->setFixedBilling($timeslot->getHourlyBilling() * $timeslot->getMinutes() / 60);
                 }
                 if ($timeslot->getBillingId() == 0 && ($timeslot->getHourlyBilling() > 0 || $timeslot->getFixedBilling() > 0)) {
                     $timeslot->setBillingId($timeslot->getUser()->getDefaultBillingId());
                 }
             }
             DB::beginWork();
             $timeslot->save();
             $timeslot_time = ($timeslot->getEndTime()->getTimestamp() - ($timeslot->getStartTime()->getTimestamp() + $timeslot->getSubtract())) / 3600;
             $task = ProjectTasks::findById($timeslot->getRelObjectId());
             if ($task->getTimeEstimate() > 0) {
                 $timeslot_percent = round($timeslot_time * 100 / ($task->getTimeEstimate() / 60));
                 $total_percentComplete = $timeslot_percent + $task->getPercentCompleted();
                 if ($total_percentComplete < 0) {
                     $total_percentComplete = 0;
                 }
                 $task->setPercentCompleted($total_percentComplete);
                 $task->save();
             }
             $this->notifier_work_estimate($task);
             DB::commit();
             flash_success(lang('success edit timeslot'));
             ajx_current("back");
         } catch (Exception $e) {
             DB::rollback();
             Logger::log($e->getTraceAsString());
             flash_error(lang('error edit timeslot') . ": " . $e->getMessage());
             ajx_current("empty");
         }
     }
 }
 /**
  * Return manager instance
  *
  * @access protected
  * @param void
  * @return BillingCategories 
  */
 function manager()
 {
     if (!$this->manager instanceof BillingCategories) {
         $this->manager = BillingCategories::instance();
     }
     return $this->manager;
 }
Example #18
0
 function getDefaultBilling()
 {
     if (is_null($this->default_billing) && $this->getDefaultBillingId() != false) {
         $this->default_billing = BillingCategories::findById($this->getDefaultBillingId());
     }
     // if
     return $this->default_billing;
 }
 function edit_timeslot()
 {
     ajx_current("empty");
     $timeslot_data = array_var($_POST, 'timeslot');
     $timeslot = Timeslots::findById(array_var($timeslot_data, 'id', 0));
     if (!$timeslot instanceof Timeslot) {
         flash_error(lang('timeslot dnx'));
         return;
     }
     //context permissions or members
     $member_ids = json_decode(array_var($_POST, 'members', array()));
     // clean member_ids
     $tmp_mids = array();
     foreach ($member_ids as $mid) {
         if (!is_null($mid) && trim($mid) != "") {
             $tmp_mids[] = $mid;
         }
     }
     $member_ids = $tmp_mids;
     if (empty($member_ids)) {
         if (!can_add(logged_user(), active_context(), Timeslots::instance()->getObjectTypeId())) {
             flash_error(lang('no access permissions'));
             ajx_current("empty");
             return;
         }
     } else {
         if (count($member_ids) > 0) {
             $enteredMembers = Members::findAll(array('conditions' => 'id IN (' . implode(",", $member_ids) . ')'));
         } else {
             $enteredMembers = array();
         }
         if (!can_add(logged_user(), $enteredMembers, Timeslots::instance()->getObjectTypeId())) {
             flash_error(lang('no access permissions'));
             ajx_current("empty");
             return;
         }
     }
     try {
         $hoursToAdd = array_var($timeslot_data, 'hours', 0);
         $minutes = array_var($timeslot_data, 'minutes', 0);
         if (strpos($hoursToAdd, ',') && !strpos($hoursToAdd, '.')) {
             $hoursToAdd = str_replace(',', '.', $hoursToAdd);
         }
         if (strpos($hoursToAdd, ':') && !strpos($hoursToAdd, '.')) {
             $pos = strpos($hoursToAdd, ':') + 1;
             $len = strlen($hoursToAdd) - $pos;
             $minutesToAdd = substr($hoursToAdd, $pos, $len);
             if (!strlen($minutesToAdd) <= 2 || !strlen($minutesToAdd) > 0) {
                 $minutesToAdd = substr($minutesToAdd, 0, 2);
             }
             $mins = $minutesToAdd / 60;
             $hours = substr($hoursToAdd, 0, $pos - 1);
             $hoursToAdd = $hours + $mins;
         }
         if ($minutes) {
             $min = str_replace('.', '', $minutes / 6);
             $hoursToAdd = $hoursToAdd + ("0." . $min);
         }
         if ($hoursToAdd <= 0) {
             flash_error(lang('time has to be greater than 0'));
             return;
         }
         $startTime = getDateValue(array_var($timeslot_data, 'date'));
         $startTime = $startTime->add('h', 8 - logged_user()->getTimezone());
         $endTime = getDateValue(array_var($timeslot_data, 'date'));
         $endTime = $endTime->add('h', 8 - logged_user()->getTimezone() + $hoursToAdd);
         $timeslot_data['start_time'] = $startTime;
         $timeslot_data['end_time'] = $endTime;
         $timeslot_data['name'] = $timeslot_data['description'];
         //Only admins can change timeslot user
         if (!array_var($timeslot_data, 'contact_id') && !logged_user()->isAdministrator()) {
             $timeslot_data['contact_id'] = $timeslot->getContactId();
         }
         $timeslot->setFromAttributes($timeslot_data);
         $user = Contacts::findById($timeslot_data['contact_id']);
         $billing_category_id = $user->getDefaultBillingId();
         $bc = BillingCategories::findById($billing_category_id);
         if ($bc instanceof BillingCategory) {
             $timeslot->setBillingId($billing_category_id);
             $hourly_billing = $bc->getDefaultValue();
             $timeslot->setHourlyBilling($hourly_billing);
             $timeslot->setFixedBilling($hourly_billing * $hoursToAdd);
             $timeslot->setIsFixedBilling(false);
         }
         DB::beginWork();
         $timeslot->save();
         $member_ids = json_decode(array_var($_POST, 'members', ''));
         $object_controller = new ObjectController();
         $object_controller->add_to_members($timeslot, $member_ids);
         DB::commit();
         ApplicationLogs::createLog($timeslot, ApplicationLogs::ACTION_EDIT);
         ajx_extra_data(array("timeslot" => $timeslot->getArrayInfo()));
     } catch (Exception $e) {
         DB::rollback();
         flash_error($e->getMessage());
     }
     // try
 }
 /**
  * Edit logged user profile. 
  * Called with different POST format from "administration/users/edit user profile " and from "profile/edit my profile" 
  *
  * @access public
  * @param void
  * @return null
  */
 function edit_profile()
 {
     ajx_set_panel("");
     $user = Contacts::findById(get_id());
     if (!($user instanceof Contact && $user->isUser()) || $user->getDisabled()) {
         flash_error(lang('user dnx'));
         ajx_current("empty");
         return;
     }
     // if
     $company = $user->getCompany();
     /*if(!($company instanceof Contact)) {
     			flash_error(lang('company dnx'));
     			ajx_current("empty");
     			return;
     		} // if
     		*/
     if (!$user->canUpdateProfile(logged_user())) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     // if
     $redirect_to = array_var($_GET, 'redirect_to');
     if (trim($redirect_to) == '' || !is_valid_url($redirect_to)) {
         $redirect_to = $user->getCardUserUrl();
     }
     // if
     tpl_assign('redirect_to', null);
     $user_data = array_var($_POST, 'user');
     if (!is_array($user_data)) {
         $user_data = array('username' => $user->getUsername(), 'email' => $user->getEmailAddress(), 'display_name' => $user->getObjectName(), 'timezone' => $user->getTimezone(), 'company_id' => $user->getCompanyId(), 'is_admin' => $user->isAdministrator(), 'type' => $user->getUserType());
         // array
     }
     // if
     tpl_assign('user', $user);
     tpl_assign('company', $company);
     tpl_assign('user_data', $user_data);
     tpl_assign('billing_categories', BillingCategories::findAll());
     // Permission Groups
     $groups = PermissionGroups::getNonPersonalSameLevelPermissionsGroups('`parent_id`,`id` ASC');
     tpl_assign('groups', $groups);
     $roles = SystemPermissions::getAllRolesPermissions();
     tpl_assign('roles', $roles);
     $tabs = TabPanelPermissions::getAllRolesModules();
     tpl_assign('tabs_allowed', $tabs);
     // Submit user
     if (is_array(array_var($_POST, 'user'))) {
         $company_id = array_var($user_data, 'company_id');
         if ($company_id && !Contacts::findById($company_id) instanceof Contact) {
             ajx_current("empty");
             flash_error(lang("company dnx"));
             return;
         }
         try {
             DB::beginWork();
             $user->setUserType(array_var($user_data, 'type'));
             $user->setTimezone(array_var($user_data, 'timezone'));
             $user->setDefaultBillingId(array_var($user_data, 'default_billing_id'));
             $user->setUpdatedOn(DateTimeValueLib::now());
             if (logged_user()->isAdministrator()) {
                 //if ($user->getId() != 2) { // System admin cannot change it's company (from Feng 2.0 onwards administrador has id = 2)
                 //	$user->setCompanyId(array_var($user_data,'company_id'));
                 //}
                 $user->setUsername(array_var($user_data, 'username'));
             } else {
                 $user->setCompanyId(array_var($user_data, 'company_id'));
             }
             if (!isset($_POST['sys_perm'])) {
                 $rol_permissions = SystemPermissions::getRolePermissions(array_var($user_data, 'type'));
                 $_POST['sys_perm'] = array();
                 $not_rol_permissions = SystemPermissions::getNotRolePermissions(array_var($user_data, 'type'));
                 foreach ($not_rol_permissions as $npr) {
                     $_POST['sys_perm'][$npr] = 0;
                 }
                 foreach ($rol_permissions as $pr) {
                     $_POST['sys_perm'][$pr] = 1;
                 }
             }
             if (!isset($_POST['mod_perm'])) {
                 $tabs_permissions = TabPanelPermissions::getRoleModules(array_var($user_data, 'type'));
                 $_POST['mod_perm'] = array();
                 foreach ($tabs_permissions as $pr) {
                     $_POST['mod_perm'][$pr] = 1;
                 }
             }
             $user->save();
             $autotimezone = array_var($user_data, 'autodetect_time_zone', null);
             if ($autotimezone !== null) {
                 set_user_config_option('autodetect_time_zone', $autotimezone, $user->getId());
             }
             $object_controller = new ObjectController();
             $object_controller->add_custom_properties($user);
             $ret = null;
             Hook::fire('after_edit_profile', $user, $ret);
             $pg_id = $user->getPermissionGroupId();
             save_permissions($pg_id, $user->isGuest());
             DB::commit();
             flash_success(lang('success update profile'));
             ajx_current("back");
             ajx_add("overview-panel", "reload");
         } catch (Exception $e) {
             DB::rollback();
             ajx_current("empty");
             flash_error($e->getMessage());
         }
         // try
     }
     // if
 }
 function close($description = null)
 {
     if ($this->isPaused()) {
         $this->setEndTime($this->getPausedOn());
     } else {
         $dt = DateTimeValueLib::now();
         $this->setEndTime($dt);
     }
     //Billing
     $user = Contacts::findById(array_var($timeslot_data, 'contact_id', logged_user()->getId()));
     $billing_category_id = $user->getDefaultBillingId();
     $bc = BillingCategories::findById($billing_category_id);
     if ($bc instanceof BillingCategory) {
         $this->setBillingId($billing_category_id);
         $hourly_billing = $bc->getDefaultValue();
         $this->setHourlyBilling($hourly_billing);
         $this->setFixedBilling(number_format($hourly_billing * $hours, 2));
         $this->setIsFixedBilling(false);
     }
     if ($description) {
         $this->setDescription($description);
     }
 }
 function assign_users()
 {
     if (!logged_user()->isAdministrator()) {
         flash_error(lang("no access permissions"));
         ajx_current("empty");
         return;
     }
     $users_data = array_var($_POST, 'users');
     if (is_array($users_data)) {
         try {
             DB::beginWork();
             foreach ($users_data as $user_id => $user_billing) {
                 $user = Users::findById($user_id);
                 if ($user_billing != $user->getDefaultBillingId()) {
                     $user->setDefaultBillingId($user_billing);
                     $user->save();
                 }
             }
             DB::commit();
             flash_success(lang("success assign user billing categories"));
             ajx_current("back");
         } catch (Exception $e) {
             DB::rollback();
             flash_error($e->getMessage());
             ajx_current("empty");
         }
     }
     tpl_assign('users_by_company', Users::getGroupedByCompany());
     tpl_assign('billing_categories', BillingCategories::findAll());
 }
 function total_task_times_p()
 {
     //set params from config options
     $report_data['date_type'] = user_config_option('timeReportDate');
     $now_date = DateTimeValueLib::now();
     if (strtotime(user_config_option('timeReportDateStart'))) {
         //this return null if date is 0000-00-00 00:00:00
         $report_data['start_value'] = user_config_option('timeReportDateStart');
     } else {
         $dateStart = format_date($now_date, DATE_MYSQL, 0);
         //today
         $report_data['start_value'] = $dateStart;
     }
     if (strtotime(user_config_option('timeReportDateEnd'))) {
         //this return null if date is 0000-00-00 00:00:00
         $report_data['end_value'] = user_config_option('timeReportDateEnd');
     } else {
         $dateEnd = format_date($now_date, DATE_MYSQL, 0);
         //today
         $report_data['end_value'] = $dateEnd;
     }
     $report_data['user'] = user_config_option('timeReportPerson');
     $report_data['timeslot_type'] = user_config_option('timeReportTimeslotType');
     $report_data['show_estimated_time'] = user_config_option('timeReportShowEstimatedTime');
     $group = explode(',', user_config_option('timeReportGroupBy'));
     $report_data['group_by_1'] = array_var($group, 0);
     $report_data['group_by_2'] = array_var($group, 1);
     $report_data['group_by_3'] = array_var($group, 2);
     $altGroup = explode(',', user_config_option('timeReportAltGroupBy'));
     $report_data['alt_group_by_1'] = array_var($altGroup, 0);
     $report_data['alt_group_by_2'] = array_var($altGroup, 1);
     $report_data['alt_group_by_3'] = array_var($altGroup, 2);
     $report_data['show_billing'] = user_config_option('timeReportShowBilling');
     $cp_ids = CustomProperties::getCustomPropertyIdsByObjectType(ProjectTasks::instance()->getObjectTypeId());
     tpl_assign('has_custom_properties', count($cp_ids) > 0);
     $sel_member_ids = active_context_members(false);
     if (count($sel_member_ids) == 0) {
         $users = Contacts::getAllUsers();
     } else {
         $users = allowed_users_in_context(Timeslots::instance()->getObjectTypeId(), active_context());
     }
     $_SESSION['total_task_times_report_data'] = $report_data;
     tpl_assign('report_data', $report_data);
     tpl_assign('users', $users);
     tpl_assign('has_billing', BillingCategories::count() > 0);
 }