/**
 * Populate object inspector
 *
 * @param IInspectorImplementation $inspector
 * @param IInspector $object
 * @param IUser $user
 * @param string $interface
 */
function frosso_estimated_cost_handle_on_object_inspector(IInspectorImplementation &$inspector, IInspector &$object, IUser &$user, $interface)
{
    if ($object instanceof Milestone) {
        if ($object->assignees()->isResponsible($user) || $object->getProject()->canEdit($user)) {
            $inspector->addProperty('percent_complete', lang('Percent complete'), new MilestonePercentCompleteInspectorProperty(new RemediaMilestone($object->getId())));
            if (AngieApplication::isModuleLoaded('tracking')) {
                $inspector->addProperty('milestone_estimate', lang('Estimation'), new MilestoneEstimateInspectorProperty(new RemediaMilestone($object->getId())));
            }
        }
    }
    // if
}
 /**
  * Return tracking helper instance
  *
  * @return ITrackingImplementation
  */
 function tracking()
 {
     if ($this->tracking === false) {
         if (AngieApplication::isModuleLoaded('tracking')) {
             $this->tracking = new IMilestoneTrackingImplementation($this);
         } else {
             $this->tracking = new ITrackingImplementationStub($this);
         }
         // if
     }
     // if
     return $this->tracking;
 }
 function defineRoutes()
 {
     // Reports
     Router::map('frosso_estimated_cost_report', 'reports/frosso-ecr', array('controller' => 'frosso_estimated_cost_reports', 'action' => 'index'));
     Router::map('frosso_estimated_cost_report_run', 'reports/frosso-ecr-run', array('controller' => 'frosso_estimated_cost_reports', 'action' => 'form_run'));
     Router::map('frosso_testing_route', 'reports/frosso-test', array('controller' => 'frosso_testing', 'action' => 'index'));
     Router::map('frosso_ec_set_milestone_percent', 'projects/:project_slug/milestones/:milestone_id/percent/set', array('controller' => 'milestones_tracking', 'action' => 'set_percent'));
     // Hijacked Routes
     Router::map('project_milestones', 'projects/:project_slug/milestones', array('controller' => 'milestones_tracking', 'action' => 'index'));
     Router::map('project_milestone', 'projects/:project_slug/milestones/:milestone_id', array('controller' => 'milestones_tracking', 'action' => 'view'), array('milestone_id' => Router::MATCH_ID));
     Router::map('project_milestones_add', 'projects/:project_slug/milestones/add', array('controller' => 'milestones_tracking', 'action' => 'add'));
     Router::map('project_milestone_edit', 'projects/:project_slug/milestones/:milestone_id/edit', array('controller' => 'milestones_tracking', 'action' => 'edit'), array('milestone_id' => Router::MATCH_ID));
     Router::map('project_object_update_milestone', 'projects/:project_slug/objects/:object_id/update-milestone', array('controller' => 'milestones_tracking', 'action' => 'update_milestone'), array('object_id' => Router::MATCH_ID));
     // Tracking
     if (AngieApplication::isModuleLoaded('tracking')) {
         // prefisso, url, nome controller, nome modulo, parametri extra
         AngieApplication::getModule('tracking')->defineTrackingRoutesFor('project_milestone', 'projects/:project_slug/milestones/:milestone_id', 'milestones_tracking', FROSSO_EC_MODULE, array('milestone_id' => Router::MATCH_ID));
     }
     // if
 }
/**
 * Render object estimate value and change option
 *
 * @param array $params
 * @param Smarty $smarty
 */
function smarty_function_remedia_milestone_estimate_icon($params, &$smarty)
{
    if (AngieApplication::isModuleLoaded('tracking')) {
        $object = array_required_var($params, 'object', true, 'RemediaMilestone');
        $user = array_required_var($params, 'user', true, 'IUser');
        $id = isset($params['id']) && $params['id'] ? $params['id'] : HTML::uniqueId('object_estimate');
        $estimate = $object->tracking()->getEstimate();
        if ($estimate instanceof Estimate) {
            $estimate_value = $estimate->getValue();
            $estimate_autogenerated = $object->tracking()->isEstimateAutogenerated();
        } else {
            $estimate_value = 0;
            $estimate_autogenerated = false;
        }
        // if
        $settings = array('value' => $estimate_value, 'estimate_autogenerated' => $estimate_autogenerated, 'short_format' => array_var($params, 'short', true), 'can_change' => $object->tracking()->canEstimate($user), 'estimates_url' => $object->tracking()->getEstimatesUrl(), 'set_estimate_url' => $object->tracking()->getSetEstimateUrl());
        return '<span id="' . $id . '"></span><script type="text/javascript">$("#' . $id . '").objectEstimateIcon(' . JSON::encode($settings) . ');</script>';
    } else {
        return '';
    }
    // if
}
<?php

if (AngieApplication::isModuleLoaded('tasks_plus')) {
    require_once dirname(__FILE__) . '/TasksPlusEnabledController.class.php';
} else {
    require_once dirname(__FILE__) . '/TasksPlusDisabledController.class.php';
}
 function index()
 {
     parent::index();
     $milestones_t = Milestones::findAllByProject($this->active_project);
     $tasks_t = Tasks::findByProject($this->active_project, $this->logged_user);
     $milestones = array();
     $tasks = array();
     // voglio il task non categorizzato che inizia prima di tutti, quindi setto questo nel futuro
     $first_task_time = new DateValue(time() + time());
     $trovato = false;
     if (is_foreachable($tasks_t)) {
         foreach ($tasks_t as $task) {
             $res = array();
             $res['id'] = $task->getTaskId();
             $res['name'] = $task->getName();
             $task->complete()->describe($this->logged_user, true, true, $completion_description);
             $task_description = $task->describe($this->logged_user, true, true);
             $res['is_completed'] = $completion_description['is_completed'];
             $res['completed_on'] = $completion_description['completed_on'];
             $res['due_on'] = $completion_description['due_on'];
             // non è sempre settato
             $res['milestone_id'] = $task_description['milestone_id'] ? $task_description['milestone_id'] : 0;
             $res['created_on_d'] = $task->getCreatedOn()->getDay();
             $res['created_on_m'] = $task->getCreatedOn()->getMonth() - 1;
             $res['created_on_y'] = $task->getCreatedOn()->getYear();
             // La data di inizio non è sempre presente. Quindi se non c'è, prendo la data di creazione del task.
             // Inoltre questo campo dipende dal modulo TaskPlus
             if (AngieApplication::isModuleLoaded('tasks_plus') && TaskPlus::getStartOn($task)) {
                 $start_on = TaskPlus::getStartOn($task);
             } else {
                 $start_on = $task->getCreatedOn();
             }
             $res['start_on_d'] = $start_on->getDay();
             $res['start_on_m'] = $start_on->getMonth() - 1;
             //javascript merda parte da Gennaio = 0
             $res['start_on_y'] = $start_on->getYear();
             // giorni in più
             $days = 60 * 60 * 24 * 15;
             //15 giorni in più
             if ($completion_description['is_completed']) {
                 $completion_date = $completion_description['completed_on'];
             } else {
                 if ($completion_description['due_on']) {
                     // non è completata ma ha data di fine settata
                     $completion_date = $completion_description['due_on'];
                 } else {
                     if (!$completion_description['due_on']) {
                         // non è completata e non ha data di fine settata
                         $completion_date = $start_on->advance($days, false);
                         // (data_inizio || data_creazione) + 15 giorni
                     }
                 }
             }
             $res['finish_on_d'] = $completion_date->getDay();
             $res['finish_on_m'] = $completion_date->getMonth() - 1;
             //javascript merda parte da Gennaio = 0
             $res['finish_on_y'] = $completion_date->getYear();
             $res['durata'] = $start_on->daysBetween($completion_date) * 8;
             //giorni_differenza * ore_lavorative
             if ($res['is_completed']) {
                 $res['percent_completion'] = 100;
             } else {
                 list($total_subtasks, $open_subtasks) = ProjectProgress::getObjectProgress($task);
                 $completed_subtasks = $total_subtasks - $open_subtasks;
                 if ($open_subtasks) {
                     $res['percent_completion'] = ceil($completed_subtasks / $total_subtasks * 100);
                 } else {
                     $res['percent_completion'] = 0;
                 }
             }
             $tasks[] = $res;
             if ($res['milestone_id'] == 0 && $first_task_time->getTimestamp() > $start_on->getTimestamp()) {
                 $first_task_time = $start_on;
                 $trovato = false;
             }
         }
     }
     if ($trovato) {
         //Aggiungo la milestone per tasks non categorizzati
         $milestones[0]['id'] = 0;
         $milestones[0]['name'] = lang("Uncategorized");
         $milestones[0]['start_on_d'] = $first_task_time->getDay();
         $milestones[0]['start_on_m'] = $first_task_time->getMonth() - 1;
         $milestones[0]['start_on_y'] = $first_task_time->getYear();
         $milestones[0]['durata'] = 1;
     }
     if (is_foreachable($milestones_t)) {
         foreach ($milestones_t as $milestone) {
             $res = array();
             $res['id'] = $milestone->getId();
             $res['name'] = $milestone->getName();
             $res['start_on_d'] = $milestone->getStartOn()->getDay();
             $res['start_on_m'] = $milestone->getStartOn()->getMonth() - 1;
             //javascript merda parte da Gennaio = 0
             $res['start_on_y'] = $milestone->getStartOn()->getYear();
             $res['durata'] = ($milestone->getDueOn()->getTimestamp() - $milestone->getStartOn()->getTimestamp()) / (60 * 60 * 24) * 8;
             //giorni * ore lavorative
             $milestones[] = $res;
         }
     }
     $this->smarty->assign(array('milestones' => $milestones, 'tasks' => $tasks));
 }
 function add()
 {
     if ($this->request->isAsyncCall() || $this->request->isMobileDevice() || $this->request->isApiCall() && $this->request->isSubmitted()) {
         if (Milestones::canAdd($this->logged_user, $this->active_project)) {
             $milestone_data = $this->request->post('milestone');
             $this->smarty->assign('milestone_data', $milestone_data);
             if ($this->request->isSubmitted()) {
                 try {
                     DB::beginWork('Creating milestone @ ' . __CLASS__);
                     $this->active_milestone = new RemediaMilestone();
                     $this->active_milestone->setAttributes($milestone_data);
                     $start_on = $this->active_milestone->getStartOn();
                     if ($start_on instanceof DateValue) {
                         if (Globalization::isWeekend($start_on) || Globalization::isDayOff($start_on)) {
                             throw new Error(lang('Start date needs to be set on working day'));
                         }
                         //if
                     }
                     //if
                     $due_on = $this->active_milestone->getDueOn();
                     if ($due_on instanceof DateValue) {
                         if (Globalization::isWeekend($due_on) || Globalization::isDayOff($due_on)) {
                             throw new Error(lang('Due date needs to be set on working day'));
                         }
                         //if
                     }
                     //if
                     $this->active_milestone->setProjectId($this->active_project->getId());
                     $this->active_milestone->setCreatedBy($this->logged_user);
                     $this->active_milestone->setState(STATE_VISIBLE);
                     $this->active_milestone->setVisibility(VISIBILITY_NORMAL);
                     $this->active_milestone->save();
                     /* INIZIO frosso hack */
                     if (AngieApplication::isModuleLoaded('tracking') && TrackingObjects::canAdd($this->logged_user, $this->active_project)) {
                         $estimate_value = isset($milestone_data['estimate_value']) && $milestone_data['estimate_value'] ? (double) $milestone_data['estimate_value'] : null;
                         $estimate_job_type = isset($milestone_data['estimate_job_type_id']) && $milestone_data['estimate_job_type_id'] ? JobTypes::findById($milestone_data['estimate_job_type_id']) : null;
                         $estimate_comment = isset($milestone_data['estimate_comment']) ? $milestone_data['estimate_comment'] : null;
                         if ($estimate_value > 0 && $estimate_job_type instanceof JobType) {
                             $this->active_milestone->tracking()->setEstimate($estimate_value, $estimate_job_type, $estimate_comment, $this->logged_user);
                         } else {
                             if ($this->active_milestone->tracking()->getEstimate() instanceof Estimate) {
                                 $this->active_milestone->tracking()->setEstimate($estimate_value, $estimate_job_type, $estimate_comment, $this->logged_user);
                             }
                             // if
                         }
                         // if
                     }
                     // if
                     /* FINE frosso hack */
                     $this->active_milestone->subscriptions()->set(array_unique(array_merge((array) $this->logged_user->getId(), (array) $this->active_project->getLeaderId(), (array) array_var($milestone_data, 'subscribers', array()))), false);
                     DB::commit('Milestone created @ ' . __CLASS__);
                     $this->logged_user->notifier()->notifySubscribers($this->active_milestone, 'system/new_milestone');
                     if ($this->request->isPageCall()) {
                         $this->flash->success('Milestone ":name" has been created', array('name' => $this->active_milestone->getName()));
                         $this->response->redirectToUrl($this->active_milestone->getViewUrl());
                     } else {
                         $this->response->respondWithData($this->active_milestone, array('as' => 'milestone', 'detailed' => true));
                     }
                     // if
                 } catch (Exception $e) {
                     DB::rollback('Failed to create milestone @ ' . __CLASS__);
                     if ($this->request->isPageCall()) {
                         $this->smarty->assign('errors', $e);
                     } else {
                         $this->response->exception($e);
                     }
                     // if
                 }
                 // try
             }
             // if
         } else {
             $this->response->forbidden();
         }
         // if
     } else {
         $this->response->badRequest();
     }
     // if
 }
 function add_source_gitolite_repository()
 {
     $is_gitolite = GitoliteAdmin::is_gitolite();
     $logged_user = $this->logged_user;
     $user_id = $logged_user->getId();
     $no_key_warning = FALSE;
     $view_url = "";
     if (AngieApplication::isModuleLoaded("source") && $this->getControllerName() == 'ac_gitolite_source') {
         $do_continue = true;
     }
     if ($do_continue) {
         // Add Administrator , Leaders and Project Manager in allowed people list
         //$role = new Roles();
         //$admins = $role::findAdministrators();
         $usrobj = new Users();
         $users_details = $usrobj->findAdministrators();
         if (is_foreachable($users_details)) {
             foreach ($users_details as $key => $value) {
                 // check key exists
                 $user_keys = GitoliteAc::check_keys_added($value->getId());
                 if ($user_keys > 0) {
                     $user_detail_permissions[$value->getId()] = array('readaccess' => 0, 'writeaccess' => 0, 'writeaccessplus' => 1, 'user_keys' => $user_keys);
                     $allowed_users[$value->getId()] = $value->getDisplayName();
                 }
             }
         }
         $this->response->assign(array('curr_users' => $allowed_users, 'user_detail_permissions' => $user_detail_permissions, 'form_action' => Router::assemble('add_source_gitolite_repository'), 'noaccess' => GITOLITE_NOACCESS, 'readaccess' => GITOLITE_READACCESS, 'manageaccess' => GITOLITE_MANAGEACCESS, 'is_gitolite' => $is_gitolite, 'no_key_warning' => $no_key_warning, 'view_url' => $view_url));
     } else {
         $this->response->assign(array('add_error' => TRUE));
     }
     if ($this->request->isSubmitted()) {
         // check for form submission
         try {
             /* Check form with validation error */
             $repository_data = $this->request->post('repository');
             if (!isset($repository_data["repo_notification_setting"])) {
                 $repository_data["repo_notification_setting"] = "no";
             }
             $errors = new ValidationErrors();
             $post_data = $this->request->post();
             $settings = GitoliteAdmin::get_admin_settings();
             $is_remote = !isset($settings["git_server_location"]) || $settings["git_server_location"] != "remote" ? false : true;
             if (!$is_remote) {
                 $sever_user_path = GitoliteAdmin::get_server_user_path();
                 if (!$sever_user_path) {
                     $errors->addError('Repository path on server invalid');
                 }
             }
             $repo_name = trim($repository_data['name']);
             $access = $post_data['access'];
             if ($repo_name == "") {
                 $errors->addError('Please enter repository name', 'repo_name');
             }
             if (!is_array($access) && count($access) == 0) {
                 $errors->addError('Select access levels for user', 'access');
             }
             /* Check for duplications repository name and Key */
             if (!$errors->hasErrors()) {
                 if (!preg_match("/^[A-Za-z0-9-]+\$/", $repo_name)) {
                     $errors->addError('Please enter valid repository name.', 'repo_name');
                 }
                 $dup_cnt = ProjectGitolite::check_source_git_dup($repository_data);
                 if (count($dup_cnt) == 0) {
                     $errors->addError('Problem occured while saving data, please try again.');
                 } elseif (count($dup_cnt) > 0) {
                     if ($dup_cnt[0]['dup_name_cnt'] > 0) {
                         $errors->addError('Repository name already used');
                     }
                 }
             }
             // if errors found throw error exception
             if ($errors->hasErrors()) {
                 throw $errors;
             }
             /** save gitolite details in database * */
             // save reponame
             try {
                 DB::beginWork('Creating a new repository @ ' . __CLASS__);
                 /**
                  * if gitolite is setup on remote, change repo path
                  */
                 if (!$is_remote) {
                     $repo_path = $sever_user_path . "/repositories/" . $repository_data['name'] . ".git";
                 } elseif ($is_remote) {
                     $repo_path = GIT_FILES_PATH . "/" . $repo_name;
                 }
                 if (is_array($post_data)) {
                     $repository_path_url = array('repository_path_url' => $repo_path);
                 }
                 $repository_data = array_merge($repository_data, $repository_path_url);
                 $clone_url = $settings['git_clone_url'] . $repo_name;
                 $this->active_repository = new GitRepository();
                 $this->active_repository->setAttributes($repository_data);
                 $this->active_repository->setCreatedBy($this->logged_user);
                 $this->active_repository->save();
                 $repo_fk = $this->active_repository->getId();
                 if ($repo_fk) {
                     $repo_id = ProjectGitolite::add_repo_details($repo_fk, 0, $user_id, $repo_path, $repository_data, $clone_url);
                     if ($repo_id) {
                         $add_access = ProjectGitolite::add_access_levels($repo_id, serialize($post_data['access']), $user_id, 1);
                         if ($add_access) {
                             $res = ProjectGitolite::render_conf_file();
                             $dir = $settings['gitoliteadminpath'] . "gitolite-admin";
                             $command = "cd " . $dir . " && git add * && git commit -am 'render conf file' && git push  || echo 'Not found'";
                             exec($command, $output, $return_var);
                             if ($is_remote) {
                                 $git_server = $settings['gitoliteuser'] . "@" . $settings['gitoliteserveradd'];
                                 //$command = "cd ".$settings['gitoliteadminpath']." && git clone ".$git_server.":".$repo_name;
                                 chdir(GIT_FILES_PATH);
                                 $command = "git clone " . $git_server . ":" . $repo_name;
                                 exec($command, $output, $return_var);
                             }
                         } else {
                             $errors->addError('Error while saving access levels.');
                             throw $errors;
                         }
                     } else {
                         $errors->addError('Error while saving repository.');
                         throw $errors;
                     }
                 } else {
                     $errors->addError('Error while saving repository.');
                     throw $errors;
                 }
                 DB::commit('Repository created @ ' . __CLASS__);
                 $this->response->respondWithData($this->active_repository, array('as' => 'repository'));
             } catch (Exception $e) {
                 DB::rollback('Failed to create a repository @ ' . __CLASS__);
                 $this->response->exception($e);
             }
         } catch (Exception $e) {
             DB::rollback('Failed to create a repository @ ' . __CLASS__);
             $this->response->exception($e);
         }
     }
 }
 /**
  * Edit gitolite repository access levels
  * @throws ValidationErrors
  */
 function edit_git_repo()
 {
     $repo_id = array_var($_GET, 'project_source_repository_id');
     //project objects id
     $is_gitolite = GitoliteAdmin::is_gitolite();
     if (!ProjectSourceRepositories::canAdd($this->logged_user, $this->active_project)) {
         $this->response->forbidden();
     }
     // if
     $project = $this->active_project;
     $project_id = $project->getId();
     $logged_user = $this->logged_user;
     $user_id = $logged_user->getId();
     $no_key_warning = FALSE;
     // to give warning if logged in user has not added his public key
     if (AngieApplication::isModuleLoaded("source") && $this->getControllerName() == 'project_tracking_gitolite') {
         $do_continue = true;
     }
     if ($do_continue) {
         $users_details = $this->active_project->users()->describe($this->logged_user, true, true, STATE_VISIBLE);
         $repo_details = ProjectGitolite::get_repo_details($repo_id);
         /* print_r($repo_details);
            die(); */
         $repository_data = $this->request->post('repository');
         if (!is_array($repository_data)) {
             $repository_data = array('updatetype' => $this->active_repository->getFieldValue("update_type"), 'visibility' => $this->project_object_repository->getVisibility());
         }
         // if
         if (is_array($repo_details) && count($repo_details) > 0) {
             // repository id from integer_field_1 in project_objects , we are saving this id in our tables.
             $git_repo_id = $repo_details['repo_id'];
             $access_array = ProjectGitolite::get_access_levels($git_repo_id);
             //$result_access = DB::execute("SELECT * from $access_table_name where repo_id = '".$repo_details['repo_id']."'");
             if (is_array($access_array) && count($access_array) > 0) {
                 $access = $access_array['permissions'];
                 $permissions = @unserialize($access);
                 if ($permissions !== false || $permissions === 'b:0;') {
                     $permissions_array = $permissions;
                 } else {
                     $permissions_array = array();
                 }
             } else {
                 $this->response->forbidden();
             }
         } else {
             $this->response->forbidden();
         }
         //print_r($permissions_array);
         $user_detail_permissions = array();
         $view_url = false;
         if (is_foreachable($users_details)) {
             foreach ($users_details as $key => $value) {
                 // check key exists
                 $user_keys = GitoliteAc::check_keys_added($value['user']['id']);
                 if ($user_keys > 0) {
                     $user_detail_permissions[$value['user']['id']] = array('readaccess' => $permissions_array[$value['user']['id']] == "2" ? TRUE : FALSE, 'writeaccess' => $permissions_array[$value['user']['id']] == "3" ? TRUE : FALSE, 'writeaccessplus' => $permissions_array[$value['user']['id']] == "3" ? TRUE : FALSE, 'user_keys' => $user_keys);
                     $allowed_users[$value['user']['id']] = $value['user']['name'];
                 }
             }
         }
         if (!isset($user_detail_permissions[$user_id]) && ($this->logged_user->isAdministrator() || $this->logged_user->isProjectManager())) {
             $repoobj = new ProjectSourceRepositories();
             $objuser = new rtmUser($user_id);
             $user_keys = GitoliteAc::check_keys_added($user_id);
             if ($user_keys) {
                 $user_detail_permissions[$user_id] = array('readaccess' => $permissions_array[$user_id] == "2" ? TRUE : $repoobj->canAccess($objuser, $project), 'writeaccess' => $permissions_array[$user_id] == "3" ? TRUE : $repoobj->canAdd($objuser, $project), 'writeaccessplus' => $permissions_array[$user_id] == "3" ? TRUE : $repoobj->canManage($objuser, $project), 'user_keys' => $user_keys);
                 $allowed_users[$user_id] = $logged_user->getName();
             } else {
                 $no_key_warning = TRUE;
                 $view_url = $this->logged_user->getViewUrl();
             }
         }
         $this->response->assign(array('curr_users' => $allowed_users, 'repo_details' => $repo_details, 'user_detail_permissions' => $user_detail_permissions, 'form_action' => Router::assemble('edit_git_repository', array('project_slug' => $project->getSlug(), 'project_source_repository_id' => $repo_id)), 'noaccess' => GITOLITE_NOACCESS, 'readaccess' => GITOLITE_READACCESS, 'manageaccess' => GITOLITE_MANAGEACCESS, 'is_gitolite' => $is_gitolite, 'no_key_warning' => $no_key_warning, 'repository_data' => $repository_data, 'view_url' => $view_url));
     } else {
         $this->response->assign(array('add_error' => TRUE));
     }
     if ($this->request->isSubmitted()) {
         // check for form submission
         try {
             /* Check form with validation error */
             $repository_data = $this->request->post('repository');
             $errors = new ValidationErrors();
             $post_data = $this->request->post();
             $settings = GitoliteAdmin::get_admin_settings();
             $sever_user_path = GitoliteAdmin::get_server_user_path();
             if (!$sever_user_path) {
                 //  $errors->addError ( 'Repository path on server invalid' );
             }
             $repo_path = $sever_user_path . "/repositories/" . $repository_data['name'] . ".git";
             $repo_name = trim($repository_data['name']);
             $access = $post_data['access'];
             if ($repo_name == "") {
                 $errors->addError('Please enter repository name', 'repo_name');
             }
             if (!is_array($access) && count($access) == 0) {
                 $errors->addError('Select access levels for user', 'access');
             }
             /* Check for duplications repository name and Key */
             if (!$errors->hasErrors()) {
                 if (!preg_match("/^[A-Za-z0-9-]+\$/", $repo_name)) {
                     $errors->addError('Please enter valid repository name.', 'repo_name');
                 }
                 /* $dup_cnt = ProjectGitolite::check_duplication($project_id,$repository_data);
                                       if(count($dup_cnt) == 0)
                                       {
                                       $errors->addError('Problem occured while saving data, please try again.');
                                       }
                                       elseif(count($dup_cnt) > 0)
                                       {
                                       if($dup_cnt[0]['dup_name_cnt'] > 0)
                                       {
                                       $errors->addError('You have already added repository with same name.');
                 
                                       }
                 
                                       } */
             }
             // if errors found throw error exception
             if ($errors->hasErrors()) {
                 throw $errors;
             }
             /** save gitolite details in database * */
             // save reponame
             try {
                 DB::beginWork('Update repository @ ' . __CLASS__);
                 $this->active_repository->setAttributes($repository_data);
                 $this->project_object_repository->setVisibility($repository_data['visibility']);
                 $this->project_object_repository->setName($repository_data['name']);
                 $this->active_repository->save();
                 $this->project_object_repository->save();
                 $repo_fk = $this->active_repository->getId();
                 if ($repo_id) {
                     $notif_setting = isset($repository_data["disable_notifications"]) ? "yes" : "no";
                     $repo_table_name = TABLE_PREFIX . "rt_gitolite_repomaster";
                     DB::execute("update {$repo_table_name} set disable_notifications = '" . $notif_setting . "' where repo_fk = '" . $repo_fk . "'");
                     $update_access = ProjectGitolite::update_access_levels($git_repo_id, serialize($post_data['access']));
                     if ($update_access) {
                         $res = ProjectGitolite::render_conf_file();
                         $dir = $settings['gitoliteadminpath'] . "gitolite-admin";
                         $command = "cd " . $dir . " && git add * && git commit -am 'render conf file' && git push  || echo 'Not found'";
                         exec($command, $output, $return_var);
                         /* $git_server = $settings['gitoliteuser']."@".$settings['gitoliteserveradd'];
                            $command = "cd ".$settings['gitoliteadminpath']." && git clone ".$git_server.":".$repo_name;
                            exec($command,$output,$return_var); */
                     } else {
                         $errors->addError('Error while saving access levels.');
                         throw $errors;
                     }
                 } else {
                     $errors->addError('Error while saving repository.');
                     throw $errors;
                 }
                 DB::commit('Repository created @ ' . __CLASS__);
                 $this->response->ok();
             } catch (Exception $e) {
                 DB::rollback('Failed to create a repository @ ' . __CLASS__);
                 $this->response->exception($e);
             }
         } catch (Exception $e) {
             DB::rollback('Failed to create a repository @ ' . __CLASS__);
             $this->response->exception($e);
         }
     }
 }
    /**
     * Find tasks for outline
     *
     * @param Project $project
     * @param User $user
     * @param int $state
     * @return array
     */
    static function findForOutline(Project $project, User $user, $state = STATE_VISIBLE)
    {
        $today = strtotime(date('Y-m-d'));
        $task_ids = DB::executeFirstColumn('SELECT id 
				FROM ' . TABLE_PREFIX . 'project_objects 
				WHERE project_id = ? 
				AND type = ? 
				AND state >= ? 
				AND visibility >= ? 
				AND completed_on IS NULL', $project->getId(), 'Task', $state, $user->getMinVisibility());
        if (!is_foreachable($task_ids)) {
            return false;
        }
        // if
        $tasks = DB::execute('SELECT o.id, 
				o.integer_field_1 AS task_id, 
				o.name, 
				o.body, 
				o.due_on, 
				o.date_field_1 AS start_on, 
				o.assignee_id, 
				o.priority, 
				o.visibility, 
				o.created_by_id, 
				o.label_id, 
				o.milestone_id,
				o.category_id, 
				o.completed_on, 
				o.delegated_by_id, 
				o.state, 
				o.created_on, 
				o.updated_on,
				o.due_on,
				u.first_name,
				u.last_name 
				FROM ' . TABLE_PREFIX . 'project_objects o LEFT JOIN ' . TABLE_PREFIX . 'users u ON(o.assignee_id=u.id) 
				WHERE o.ID IN(?) ORDER BY ' . self::$task_order_by . ' ' . self::$task_sort_by, $task_ids);
        // casting
        // 		$tasks->setCasting(array(
        // 				'due_on'        => DBResult::CAST_DATE,
        // 				'start_on'      => DBResult::CAST_DATE
        // 		));
        $tasks_id_prefix_pattern = '--TASK-ID--';
        $task_url_params = array('project_slug' => $project->getSlug(), 'task_id' => $tasks_id_prefix_pattern);
        $view_task_url_pattern = Router::assemble('project_task', $task_url_params);
        $edit_task_url_pattern = Router::assemble('project_task_edit', $task_url_params);
        $trash_task_url_pattern = Router::assemble('project_task_trash', $task_url_params);
        $subscribe_task_url_pattern = Router::assemble('project_task_subscribe', $task_url_params);
        $unsubscribe_task_url_pattern = Router::assemble('project_task_unsubscribe', $task_url_params);
        $reschedule_task_url_pattern = Router::assemble('project_task_reschedule', $task_url_params);
        $tracking_task_url_pattern = Router::assemble('project_task_tracking', $task_url_params);
        // can_manage_tasks
        $can_manage_tasks = $user->projects()->getPermission('task', $project) >= ProjectRole::PERMISSION_MANAGE;
        // all assignees
        $user_assignments_on_tasks = DB::executeFirstColumn('SELECT parent_id FROM ' . TABLE_PREFIX . 'assignments WHERE parent_id IN (?) AND parent_type = ? AND user_id = ?', $task_ids, 'Task', $user->getId());
        // all subscriptions
        $user_subscriptions_on_tasks = DB::executeFirstColumn('SELECT parent_id FROM ' . TABLE_PREFIX . 'subscriptions WHERE parent_id IN (?) AND parent_type = ? AND user_id = ?', $task_ids, 'Task', $user->getId());
        // other assignees
        $other_assignees = array();
        $raw_other_assignees = DB::execute('SELECT user_id, parent_id FROM ' . TABLE_PREFIX . 'assignments WHERE parent_type = ? AND parent_id IN (?)', 'Task', $task_ids);
        foreach ($raw_other_assignees as $raw_assignee) {
            if (!is_array($other_assignees[$raw_assignee['parent_id']])) {
                $other_assignees[$raw_assignee['parent_id']] = array();
            }
            // if
            $other_assignees[$raw_assignee['parent_id']][] = array('id' => $raw_assignee['user_id']);
        }
        // foreach
        // expenses & time
        $expenses = array();
        $time = array();
        $estimates = array();
        if (AngieApplication::isModuleLoaded('tracking')) {
            $raw_expenses = DB::execute('SELECT parent_id, SUM(value) as expense FROM ' . TABLE_PREFIX . 'expenses WHERE parent_id IN (?) AND parent_type = ? GROUP BY parent_id', $task_ids, 'Task');
            if (is_foreachable($raw_expenses)) {
                foreach ($raw_expenses as $raw_expense) {
                    $expenses[$raw_expense['parent_id']] = $raw_expense['expense'];
                }
                // if
            }
            // if
            $raw_time = DB::execute('SELECT parent_id, SUM(value) as time FROM ' . TABLE_PREFIX . 'time_records WHERE parent_id IN (?) AND parent_type = ? GROUP BY parent_id', $task_ids, 'Task');
            if (is_foreachable($raw_time)) {
                foreach ($raw_time as $raw_single_time) {
                    $time[$raw_single_time['parent_id']] = $raw_single_time['time'];
                }
                // foreach
            }
            // if
            $raw_estimates = DB::execute('SELECT parent_id, value, job_type_id FROM (SELECT * FROM ' . TABLE_PREFIX . 'estimates WHERE parent_id IN (?) AND parent_type = ? ORDER BY created_on DESC) as estimates_inverted GROUP BY parent_id', $task_ids, 'Task');
            if (is_foreachable($raw_estimates)) {
                foreach ($raw_estimates as $raw_estimate) {
                    $estimates[$raw_estimate['parent_id']] = array('value' => $raw_estimate['value'], 'job_type_id' => $raw_estimate['job_type_id']);
                }
                // foreach
            }
            // if
        }
        // if
        $task_url = Router::assemble('project_task', array('project_slug' => $project->getSlug(), 'task_id' => '--TASKID--'));
        $project_id = $project->getId();
        $labels = Labels::getIdDetailsMap('AssignmentLabel');
        $results = array();
        foreach ($tasks as $subobject) {
            $task_id = array_var($subobject, 'id');
            $task_task_id = array_var($subobject, 'task_id');
            list($total_subtasks, $open_subtasks) = ProjectProgress::getObjectProgress(array('project_id' => $project_id, 'object_type' => 'Task', 'object_id' => $subobject['id']));
            $results[] = array('id' => $task_id, 'task_id' => $task_task_id, 'name' => array_var($subobject, 'name'), 'body' => array_var($subobject, 'body'), 'priority' => array_var($subobject, 'priority'), 'milestone_id' => array_var($subobject, 'milestone_id', null), 'class' => 'Task', 'start_on' => array_var($subobject, 'start_on'), 'assignee_id' => array_var($subobject, 'assignee_id'), 'other_assignees' => array_var($other_assignees, $task_id, null), 'label_id' => array_var($subobject, 'label_id', null), 'label' => $subobject['label_id'] ? $labels[$subobject['label_id']] : null, 'project_id' => $project_id, 'category_id' => $subobject['category_id'], 'is_completed' => $subobject['completed_on'] ? 1 : 0, 'permalink' => str_replace('--TASKID--', $subobject['task_id'], $task_url), 'priority' => self::$priority_map[$subobject['priority']], 'delegated_by_id' => $subobject['delegated_by_id'], 'total_subtasks' => $total_subtasks, 'open_subtasks' => $open_subtasks, 'is_favorite' => Favorites::isFavorite(array('Task', $task_id), $user), 'is_archived' => $subobject['state'] == STATE_ARCHIVED ? 1 : 0, 'visibility' => $subobject['visibility'], 'created_on' => $subobject['created_on'] ? $subobject['created_on'] : $subobject['updated_on'], 'updated_on' => $subobject['updated_on'], 'assignee_name' => $subobject['first_name'] . " " . $subobject['last_name'], 'due_on' => $subobject['due_on'] ? $subobject['due_on'] : lang('No due date set'), 'stato' => $subobject['due_on'] ? $subobject['due_on'] >= $today ? 'orario' : 'ritardo' : 'not_set', 'user_is_subscribed' => in_array($task_id, $user_subscriptions_on_tasks), 'object_time' => array_var($time, $task_id, 0), 'object_expenses' => array_var($expenses, $task_id, 0), 'estimate' => array_var($estimates, $task_id, null), 'event_names' => array('updated' => 'task_updated'), 'urls' => array('view' => str_replace($tasks_id_prefix_pattern, $task_task_id, $view_task_url_pattern), 'edit' => str_replace($tasks_id_prefix_pattern, $task_task_id, $edit_task_url_pattern), 'trash' => str_replace($tasks_id_prefix_pattern, $task_task_id, $trash_task_url_pattern), 'subscribe' => str_replace($tasks_id_prefix_pattern, $task_task_id, $subscribe_task_url_pattern), 'unsubscribe' => str_replace($tasks_id_prefix_pattern, $task_task_id, $unsubscribe_task_url_pattern), 'reschedule' => str_replace($tasks_id_prefix_pattern, $task_task_id, $reschedule_task_url_pattern), 'tracking' => str_replace($tasks_id_prefix_pattern, $task_task_id, $tracking_task_url_pattern)), 'permissions' => array('can_edit' => can_edit_project_object($subobject, $user, $project, $can_manage_tasks, $user_assignments_on_tasks), 'can_trash' => can_trash_project_object($subobject, $user, $project, $can_manage_tasks, $user_assignments_on_tasks)));
        }
        // foreach
        return $results;
    }