예제 #1
0
 /**
  * Validate before save
  *
  * @param ValidationErrors $errors
  * @return null
  */
 function validate(&$errors)
 {
     if (!$this->validatePresenceOf('name')) {
         $errors->addError(lang('Tax Rate name is required'), 'name');
     }
     // if
 }
예제 #2
0
 /**
  * Validate before save
  *
  * @param ValidationErrors $errors
  * @return null
  */
 function validate(&$errors)
 {
     if (!$this->validatePresenceOf('user_id')) {
         $errors->addError(lang('User needs to be selected'), 'user_id');
     }
     // if
     if (!$this->validatePresenceOf('object_id')) {
         $errors->addError(lang('Object needs to be selected'), 'object_id');
     }
     // if
 }
 /**
  * Validate model
  *
  * @param ValidationErrors $errors
  * @return null
  */
 function validate(&$errors)
 {
     if (!$this->validatePresenceOf('name')) {
         $errors->addError(lang('Note name is required'), 'description');
     }
     // if
     if (!$this->validatePresenceOf('content')) {
         $errors->addError(lang('Note content is required'), 'unit_cost');
     }
     // if
     return parent::validate($errors);
 }
 /**
  * Validate model
  *
  * @param ValidationErrors $errors
  * @return null
  */
 function validate(&$errors)
 {
     if (!$this->validatePresenceOf('description')) {
         $errors->addError(lang('Description is required'), 'description');
     }
     // if
     if (!$this->getUnitCost()) {
         $this->setUnitCost(0);
     }
     // if
     if (!$this->validatePresenceOf('quantity')) {
         $errors->addError(lang('Quantity is required'), 'quantity');
     }
     // if
     return parent::validate($errors);
 }
 /**
  * Index page action
  *
  */
 function index()
 {
     if (!module_loaded('tickets')) {
         $this->redirectTo('public_submit_unavailable');
     }
     // if
     $ticket_data = $this->request->post('ticket');
     $this->smarty->assign(array('captcha_url' => ROOT_URL . '/captcha.php?id=' . md5(time()), "ticket_data" => $ticket_data));
     if ($this->request->isSubmitted()) {
         $errors = new ValidationErrors();
         if ($this->captcha_enabled) {
             //$captcha_value = array_var($_SESSION, CAPTCHA_SESSION_ID);
             if (!Captcha::Validate($ticket_data['captcha'])) {
                 $errors->addError(lang('Code you entered is not valid'), 'captcha');
                 $this->smarty->assign('errors', $errors);
             }
             // if
         }
         // if
         if (!$errors->hasErrors()) {
             $submitter = new AnonymousUser($ticket_data['created_by_name'], $ticket_data['created_by_email']);
             db_begin_work();
             $ticket = new Ticket();
             attach_from_files($ticket, $submitter);
             $ticket->setAttributes($ticket_data);
             $ticket->setProjectId($this->active_project->getId());
             $ticket->setVisibility(VISIBILITY_NORMAL);
             $ticket->setState(STATE_VISIBLE);
             $ticket->setCreatedBy($submitter);
             $save = $ticket->save();
             if (!$save || is_error($save)) {
                 unset($ticket_data['captcha']);
                 db_rollback();
                 $this->smarty->assign(array('ticket_data' => $ticket_data, 'errors' => $save));
             } else {
                 Subscriptions::subscribeUsers(array($this->active_project->getLeaderId()), $ticket);
                 db_commit();
                 $ticket->ready();
                 $this->redirectTo('public_submit_success');
             }
             // if
         }
         // if
     }
     // if
 }
 /**
  * Index page
  * 
  * @param void
  * @return null
  */
 function index()
 {
     js_assign('invoicing_precision', INVOICE_PRECISION);
     $this->wireframe->addBreadCrumb(lang('Invoicing'), assemble_url('admin'));
     $this->wireframe->addBreadCrumb(lang('Number Generator'), assemble_url('admin_invoicing_number'));
     // prepare javascript variables and counters for preview
     $pattern = Invoices::getInvoiceNumberGeneratorPattern();
     list($total_counter, $year_counter, $month_counter) = Invoices::getDateInvoiceCounters();
     $total_counter++;
     $year_counter++;
     $month_counter++;
     $variable_year = date('Y');
     $variable_month = date('n');
     $variable_month_short = date('M');
     $variable_month_long = date('F');
     js_assign('pattern_variables', array(INVOICE_VARIABLE_CURRENT_YEAR => $variable_year, INVOICE_VARIABLE_CURRENT_MONTH => $variable_month, INVOICE_VARIABLE_CURRENT_MONTH_SHORT => $variable_month_short, INVOICE_VARIABLE_CURRENT_MONTH_LONG => $variable_month_long, INVOICE_NUMBER_COUNTER_TOTAL => $total_counter, INVOICE_NUMBER_COUNTER_YEAR => $year_counter, INVOICE_NUMBER_COUNTER_MONTH => $month_counter));
     $generator_data = $this->request->post('generator');
     if (!is_foreachable($generator_data)) {
         $generator_data = array('pattern' => Invoices::getinvoiceNumberGeneratorPattern());
     }
     // if
     $this->smarty->assign(array('generator_data' => $generator_data));
     if ($this->request->isSubmitted()) {
         $errors = new ValidationErrors();
         $posted_pattern = array_var($generator_data, 'pattern', null);
         if (!trim($posted_pattern)) {
             $errors->addError(lang('Pattern is required'), 'pattern');
         }
         // if
         if (strpos($posted_pattern, INVOICE_NUMBER_COUNTER_TOTAL) === false && strpos($posted_pattern, INVOICE_NUMBER_COUNTER_YEAR) === false && strpos($posted_pattern, INVOICE_NUMBER_COUNTER_MONTH) === false) {
             $errors->addError(lang('One of invoice counters is required (:total, :year, :month)', array('total' => INVOICE_NUMBER_COUNTER_TOTAL, 'year' => INVOICE_NUMBER_COUNTER_YEAR, 'month' => INVOICE_NUMBER_COUNTER_MONTH)), 'pattern');
         }
         // if
         if ($errors->hasErrors()) {
             $this->smarty->assign(array('errors' => $errors));
         } else {
             Invoices::setInvoiceNumberGeneratorPattern($posted_pattern);
             flash_success('Pattern for invoice number generator is saved');
             $this->redirectTo('admin');
         }
         // if
     }
     // if
 }
 /**
  * Validate before save
  *
  * @param ValidationErrors $errors
  * @return null
  */
 function validate(&$errors)
 {
     if (!$this->validatePresenceOf('module')) {
         $errors->addError(lang('Module name is required'), 'module');
     }
     // if
     if ($this->validatePresenceOf('name')) {
         if (!$this->validateUniquenessOf('name')) {
             $errors->addError(lang('Option name must be unique'), 'name');
         }
         // if
     } else {
         $errors->addError(lang('Option name is required'), 'name');
     }
     // if
     if (!$this->validatePresenceOf('type')) {
         $errors->addError(lang('Option type is required'), 'type');
     }
     // if
 }
예제 #8
0
 /**
  * Validate before save
  *
  * @param ValidationErrors $errors
  * @return null
  */
 function validate(&$errors)
 {
     if ($this->validatePresenceOf('name')) {
         if (!$this->validateUniquenessOf('name')) {
             $errors->addError(lang('Currency name needs to be unqiue'), 'name');
         }
         // if
     } else {
         $errors->addError(lang('Currency name is required'), 'name');
     }
     // if
     if ($this->validatePresenceOf('code')) {
         if (!$this->validateUniquenessOf('code')) {
             $errors->addError(lang('Currency code needs to be unqiue'), 'code');
         }
         // if
     } else {
         $errors->addError(lang('Currency code is required'), 'code');
     }
     // if
 }
 /**
  * Edit Project Icon
  *
  * @param void
  * @return null
  */
 function edit_icon()
 {
     if ($this->active_project->isNew()) {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     // if
     if (!$this->active_project->canEdit($this->logged_user)) {
         $this->httpError(HTTP_ERR_FORBIDDEN);
     }
     // if
     if (!extension_loaded('gd')) {
         $message = lang('<b>GD not Installed</b> - GD extension is not installed on your system. You will not be able to upload project icons, company logos and avatars!');
         if ($this->request->isAsyncCall()) {
             echo "<p>{$message}</p>";
             die;
         } else {
             $this->wireframe->addPageMessage($message, PAGE_MESSAGE_ERROR);
         }
         // if
     }
     // if
     if ($this->request->isSubmitted()) {
         if (!isset($_FILES['icon']) || !is_uploaded_file($_FILES['icon']['tmp_name'])) {
             $message = lang('Please select an image');
             if ($this->request->isAsyncCall()) {
                 $this->httpError(HTTP_ERR_OPERATION_FAILED, $message);
             } else {
                 flash_error($message);
                 $this->redirectToUrl($this->active_project->getEditIconUrl());
             }
             // if
         }
         // if
         if (can_resize_images()) {
             $errors = new ValidationErrors();
             do {
                 $from = WORK_PATH . '/' . make_password(10) . '_' . $_FILES['icon']['name'];
             } while (is_file($from));
             if (!move_uploaded_file($_FILES['icon']['tmp_name'], $from)) {
                 $errors->addError(lang("Can't copy image to work path"), 'icon');
             } else {
                 if (FIX_UPLOAD_PERMISSION !== false) {
                     @chmod($from, FIX_UPLOAD_PERMISSION);
                 }
                 // if
                 // small avatar
                 $to = $this->active_project->getIconPath();
                 $small = scale_image($from, $to, 16, 16, IMAGETYPE_GIF);
                 // large avatar
                 $to = $this->active_project->getIconPath(true);
                 $large = scale_image($from, $to, 40, 40, IMAGETYPE_GIF);
                 @unlink($from);
             }
             // if
             if (empty($from)) {
                 $errors->addError('Select icon', 'icon');
             }
             // if
             if ($errors->hasErrors()) {
                 $this->smarty->assign('errors', $errors);
                 $this->render();
             }
             // if
             cache_remove('project_icons');
         }
         // if
     }
     // if
 }
 /**
  * Validate before save
  *
  * @param ValidationErrors $errors
  * @return null
  */
 function validate(&$errors)
 {
     if ($this->validatePresenceOf('name', 3)) {
         if (!$this->validateUniquenessOf('name')) {
             $errors->addError(lang('Category name needs to be unique'), 'name');
         }
         // if
     } else {
         $errors->addError(lang('Category name must be at least 3 characters long'), 'name');
     }
     // if
     parent::validate($errors, true);
 }
예제 #11
0
 /**
  * Validate before save
  *
  * @param ValidationErrors $errors
  * @return null
  */
 function validate(&$errors)
 {
     if (!$this->validatePresenceOf('company_id')) {
         $errors->addError(lang('Client is required'), 'company_address');
     }
     // if
     if (!$this->validatePresenceOf('company_address')) {
         $errors->addError(lang('Client address is required'), 'company_address');
     }
     // if
     if ($this->validatePresenceOf('number')) {
         if (!$this->validateUniquenessOf('number')) {
             $errors->addError(lang('Invoice No. needs to be unqiue'), 'number');
         }
         // if
     }
     // if
 }
 /**
  * Validate before save
  *
  * @param ValidationErrors $errors
  * @return null
  */
 function validate(&$errors)
 {
     if (!$this->validatePresenceOf('paid_on')) {
         $errors->addError(lang('Payment day is required'), 'paid_on');
     }
     // if
     if ($this->validatePresenceOf('invoice_id')) {
         $invoice = $this->getInvoice();
         if (instance_of($invoice, 'Invoice')) {
             // Validate amount, only for new invoices
             if ($this->isNew()) {
                 if ($this->validatePresenceOf('amount')) {
                     if ($this->getAmount() > 0) {
                         if ((string) $this->getAmount() > (string) $invoice->getMaxPayment()) {
                             $errors->addError(lang('Amount too large'), 'amount');
                         }
                         // if
                     } else {
                         $errors->addError(lang('Payment amounts needs to be larger than 0'), 'amount');
                     }
                     // if
                 } else {
                     $errors->addError(lang('Payment amount is required'), 'amount');
                 }
                 // if
             }
             // if
         } else {
             $errors->addError(lang('Invoice is required'), 'invoice_id');
         }
         // if
     } else {
         $errors->addError(lang('Invoice is required'), 'invoice_id');
     }
     // if
 }
 /**
  * Validate before save
  *
  * @param ValidationErrors $errors
  * @return null
  */
 function validate($errors)
 {
     if ($this->validatePresenceOf('name', 3)) {
         if (!$this->validateUniquenessOf('name')) {
             $errors->addError(lang('Group name is already in use'), 'name');
         }
         // if
     } else {
         $errors->addError(lang('Group name needs to be at least 3 characters long'), 'name');
     }
     // if
 }
 /**
  * Validate before save
  *
  * @param ValidationErrors $errors
  * @return null
  */
 function validate(&$errors)
 {
     if ($this->validatePresenceOf('name')) {
         if (!$this->validateUniquenessOf('name', 'is_private')) {
             $errors->addError(lang('Filter name needs to be unique'), 'name');
         }
         // if
     } else {
         $errors->addError(lang('Field name is required'), 'name');
     }
     // if
     if ($this->getIsPrivate()) {
         if ($this->isDefault()) {
             $errors->addError(lang("Default filter can't be marked as private"), 'is_private');
             // Globally default?
         } elseif ($this->hasUsers()) {
             $errors->addError(lang("Filter already used as default by other users can't be marked as private"), 'is_private');
             // Not global default, but default for somone
         }
         // if
     }
     // if
 }
예제 #15
0
 /**
  * Validate before save
  *
  * @param ValidationErrors $errors
  * @return null
  */
 function validate(&$errors)
 {
     if (!$this->validatePresenceOf('name', 3)) {
         $errors->addError(lang('Document name must be at least 3 characters'), 'name');
     }
     // if
     if (!$this->validatePresenceOf('category_id')) {
         $errors->addError(lang('Category is required'), 'category_id');
     }
     // if
     parent::validate($errors, true);
 }
 /**
  * Function to validate class
  *
  * @param ValidationErrors $errors
  */
 function validate(&$errors)
 {
     if (!$this->validatePresenceOf('project_id')) {
         $errors->addError(lang('required'), 'project_id');
     }
     // if
     if (!$this->validatePresenceOf('object_type')) {
         $errors->addError(lang('required'), 'object_type');
     }
     // if
     if (!$this->validatePresenceOf('mailbox')) {
         $errors->addError(lang('required'), 'mailbox');
     }
     // if
     if (!$this->validatePresenceOf('username')) {
         $errors->addError(lang('required'), 'username');
     }
     // if
     if (!$this->validatePresenceOf('password')) {
         $errors->addError(lang('required'), 'password');
     }
     // if
     if (!$this->validatePresenceOf('host')) {
         $errors->addError(lang('required'), 'host');
     }
     // if
     if (!$this->validatePresenceOf('type')) {
         $errors->addError(lang('required'), 'type');
     }
     // if
     if (!$this->validatePresenceOf('security')) {
         $errors->addError(lang('required'), 'security');
     }
     // if
     if (!$this->validatePresenceOf('from_email')) {
         $errors->addError(lang('required'), 'from_email');
     } else {
         // validate that user does not exists
         $current_user = Users::findByEmail($this->getFromEmail());
         if (instance_of($current_user, 'User')) {
             $errors->addError(lang('email in use'), 'from_email');
         }
         // if
     }
     // if
     parent::validate($errors, true);
 }
예제 #17
0
 /**
  * Validate before save
  *
  * @param ValidationErrors $errors
  * @return null
  */
 function validate(&$errors)
 {
     if (!$this->validatePresenceOf('name', 3)) {
         $errors->addError(lang('Ticket summary should be at least 3 characters long'), 'name');
     }
     // if
     parent::validate($errors, true);
 }
 function add_ftp_connections()
 {
     /* $cus = new CustomFields();
               //$cus->initForType("Users",2);
               $flds = $cus->getCustomFieldsByType("Users");
     
               //$cus->initForType("Project",1);
               if(is_array($flds) && count($flds) > 0)
               {
               foreach ($flds as $key => $value) {
               $settings["$key"]["label"] = "Comments";
               $settings["$key"]["is_enabled"] = "1";
               $cus->setCustomFieldsByType("Users", $settings);
     
               }
               }
               print_r($flds);
               die(); */
     //$settings["label"];
     //$cus->setCustomFieldsByType("Project", $settings);
     $repo_branches = $this->active_repository;
     $eng = $repo_branches->getEngine($this->active_project->getId());
     //print_r($eng->getBranches);
     $branches_array = $eng->getBranches();
     $repo_branches_str = implode(",", $branches_array);
     $repo_id = array_var($_GET, 'project_source_repository_id');
     //project objects id
     $repo_obj = new ProjectSourceRepository($repo_id);
     $src_repo_id = $repo_obj->getIntegerField1();
     if ($this->request->isSubmitted()) {
         // check for form submission
         $post_data = $this->request->post();
         //print_r($post_data);
         try {
             $errors = new ValidationErrors();
             $ftpdetials = $post_data["ftpdetials"];
             $fld_cnt = count($ftpdetials["ftp_domain"]);
             //print_r($ftpdetials);
             //die();
             $array_urls = array();
             for ($i = 0; $i < $fld_cnt; $i++) {
                 if ($ftpdetials["ftp_domain"][$i] == "" || $ftpdetials["ftp_port"][$i] == "" || $ftpdetials["ftp_username"][$i] == "" || $ftpdetials["ftp_password"][$i] == "" || $ftpdetials["branches"][$i] == "" || $ftpdetials["ftp_dir"][$i] == "") {
                     $errors->addError("Please fill all connection parameters.");
                 } else {
                     $arra_conn[$i] = array("ftp_domain" => $ftpdetials["ftp_domain"][$i], "ftp_port" => $ftpdetials["ftp_port"][$i], "ftp_username" => $ftpdetials["ftp_username"][$i], "ftp_password" => $ftpdetials["ftp_password"][$i], "branches" => $ftpdetials["branches"][$i], "ftp_dir" => $ftpdetials["ftp_dir"][$i]);
                 }
                 /* if(!filter_var($value, FILTER_VALIDATE_URL) && $value != "")
                    {
                    $errors->addError("$value is not a valid URL.");
                    }
                    else
                    {
                    $array_urls[] = $value;
                    } */
             }
             if ($errors->hasErrors()) {
                 throw $errors;
             }
             DB::beginWork('Add FTP Details @ ' . __CLASS__);
             if (is_array($arra_conn) && count($arra_conn) > 0) {
                 $ftp_details_exists = ProjectGitolite::ftp_connections_exists($src_repo_id);
                 if (is_array($ftp_details_exists) && $ftp_details_exists["ftp_cnt"] > 0) {
                     $ftp_table_name = TABLE_PREFIX . "rt_ftp_connections";
                     DB::execute("DELETE FROM {$ftp_table_name} where repo_fk = '" . $src_repo_id . "'");
                 }
                 for ($i = 0; $i < $fld_cnt; $i++) {
                     $ftp_details_add = ProjectGitolite::add_ftp_details($arra_conn[$i], $src_repo_id, $this->logged_user->getId());
                     if (!$ftp_details_add) {
                         $errors->addError('Problem occured while saving data, please try again.');
                         throw $errors;
                     }
                 }
                 DB::commit('FTP details Added @ ' . __CLASS__);
                 $this->response->ok();
             } else {
                 $errors->addError("Error while saving FTP details.");
                 throw $errors;
             }
         } catch (Exception $e) {
             DB::rollback('Failed to add FTP details @ ' . __CLASS__);
             $this->response->exception($e);
         }
     }
     $ftp_details_exists = ProjectGitolite::get_connection_details($src_repo_id);
     $this->response->assign(array('repo_branches_str' => $repo_branches_str, 'branches_array' => $branches_array, 'ftp_test_url' => Router::assemble('test_ftp_conn', array('project_slug' => $this->active_project->getSlug(), 'project_source_repository_id' => $repo_id)), 'form_action' => Router::assemble('add_ftp_conn', array('project_slug' => $this->active_project->getSlug(), 'project_source_repository_id' => $repo_id)), "ftp_details_exists" => $ftp_details_exists));
 }
예제 #19
0
 /**
  * Validate before save
  *
  * @param ValidationErrors $errors
  * @return null
  */
 function validate(&$errors)
 {
     if (!$this->validatePresenceOf('name', 3)) {
         $errors->addError(lang('Milestone name is required'), 'name');
     }
     // if
     /*
     if(!$this->validatePresenceOf('start_on')) {
       $errors->addError(lang('Start date is required'), 'start_on');
     } // if
     
     if(!$this->validatePresenceOf('due_on')) {
       $errors->addError(lang('Due date is required'), 'due_on');
     } // if
     */
     $start_on = $this->getStartOn();
     $due_on = $this->getDueOn();
     if (instance_of($start_on, 'DateValue') && instance_of($due_on, 'DateValue')) {
         if (!empty($due_on->timestamp)) {
             if ($start_on->getTimestamp() > $due_on->getTimestamp()) {
                 $errors->addError(lang('Start date needs to be before due date'), 'date_range');
             }
             // if
         }
     }
     // if
     parent::validate($errors, true);
 }
예제 #20
0
 /**
  * Validate model object before save
  *
  * @param ValidationErrors $errors
  * @return null
  */
 function validate(&$errors)
 {
     if (!$this->validatePresenceOf('leader_id') && !$this->validatePresenceOf('leader_name') && !$this->validatePresenceOf('leader_email')) {
         $errors->addError(lang('Project leader is required'), 'leader_id');
     }
     // if
     if (!$this->validatePresenceOf('name', 3)) {
         $errors->addError(lang('Project name is required. Min length is 3 letters'), 'name');
     }
     // if
 }
 /**
  * Add a Github repository
  *
  * @return void
  * @return null
  **/
 function add()
 {
     if (!Repository::canAdd($this->logged_user, $this->active_project)) {
         $this->httpError(HTTP_ERR_FORBIDDEN);
     }
     // if
     $repository_data = $this->request->post('repository');
     if (!is_array($repository_data)) {
         $repository_data = array('visibility' => $this->active_project->getDefaultVisibility());
     }
     // if
     if ($this->request->isSubmitted()) {
         $repository_data['name'] = trim($repository_data['name']) == '' ? $repository_data['url'] : $repository_data['name'];
         $this->active_repository->setAttributes($repository_data);
         $this->active_repository->setBody(clean(array_var($repository_data, 'url', null)));
         $this->active_repository->setProjectId($this->active_project->getId());
         $this->active_repository->setCreatedBy($this->logged_user);
         $this->active_repository->setState(STATE_VISIBLE);
         $result = $this->active_repository->testRepositoryConnection();
         if ($result === true) {
             $save = $this->active_repository->save();
             if ($save && !is_error($save)) {
                 flash_success(lang('Project repository &quot;:name&quot; has been added successfully'), array('name' => $this->active_repository->getName()));
                 $this->redirectToUrl(github_module_url($this->active_project));
             } else {
                 $save->errors['-- any --'] = $save->errors['body'];
                 $this->smarty->assign('errors', $save);
             }
             //if
         } else {
             $errors = new ValidationErrors();
             $errors->addError(lang('Failed to connect to repository: :message', array('message' => $result)));
             $this->smarty->assign('errors', $errors);
         }
         // if
     }
     // if
     $this->smarty->assign(array('repository_data' => $repository_data));
 }
예제 #22
0
 /**
  * Validate before save
  *
  * @param ValidationErrors $errors
  * @return null
  */
 function validate(&$errors)
 {
     if (!$this->validatePresenceOf('body', 3)) {
         $errors->addError(lang('Task text is required. Min length is 3 letters'), 'body');
     }
     // if
     parent::validate($errors, true);
 }
 /**
  * Edit repository
  *
  * @param null
  * @return void
  */
 function edit()
 {
     if (!$this->active_repository->canEdit($this->logged_user)) {
         $this->httpError(HTTP_ERR_FORBIDDEN);
     }
     // if
     $repository_data = $this->request->post('repository');
     if (!is_array($repository_data)) {
         $repository_data = array('name' => $this->active_repository->getName(), 'url' => $this->active_repository->getUrl(), 'username' => $this->active_repository->getUsername(), 'password' => $this->active_repository->getPassword(), 'repositorytype' => $this->active_repository->getRepositoryType(), 'updatetype' => $this->active_repository->getUpdateType(), 'visibility' => $this->active_repository->getVisibility());
     }
     if ($this->request->isSubmitted()) {
         db_begin_work();
         $this->active_repository->setAttributes($repository_data);
         $this->active_repository->loadEngine($this->active_repository->getRepositoryType());
         $this->repository_engine = new RepositoryEngine($this->active_repository);
         $this->repository_engine->triggerred_by_handler = true;
         $result = $this->repository_engine->testRepositoryConnection();
         if ($result === true) {
             $save = $this->active_repository->save();
             if ($save && !is_error($save)) {
                 db_commit();
                 flash_success(lang('Repository has been successfully updated'));
                 $this->redirectToUrl($this->active_repository->getHistoryUrl());
             } else {
                 db_rollback();
                 $this->smarty->assign('errors', $save);
             }
             //if
         } else {
             db_rollback();
             $errors = new ValidationErrors();
             $errors->addError(lang('Failed to connect to repository: :message', array('message' => $result)));
             $this->smarty->assign('errors', $errors);
         }
         // if
     }
     // if
     js_assign('repository_test_connection_url', assemble_url('repository_test_connection', array('project_id' => $this->active_project->getId())));
     $this->smarty->assign(array('types' => $this->active_repository->types, 'update_types' => $this->active_repository->update_types, 'repository_data' => $repository_data, 'active_repository' => $this->active_repository, 'disable_url_and_type' => instance_of($this->active_repository->getLastCommit(), 'Commit'), 'aid_url' => lang('The path to the existing repository cannot be changed'), 'aid_engine' => lang('Repository type cannot be changed')));
 }
 /**
  * Mass mailer
  *
  * @param void
  * @return null
  */
 function mass_mailer()
 {
     if (!MASS_MAILER_ENABLED) {
         $this->httpError(HTTP_ERR_FORBIDDEN);
     }
     // if
     $email_data = $this->request->post('email');
     $this->smarty->assign(array('email_data' => $email_data, 'exclude' => array($this->logged_user->getId())));
     if ($this->request->isSubmitted()) {
         $errors = new ValidationErrors();
         $subject = trim(array_var($email_data, 'subject'));
         $body = trim(array_var($email_data, 'body'));
         $recipient_ids = array_var($email_data, 'recipients');
         if (empty($subject)) {
             $errors->addError(lang('Subject is required'), 'subject');
         }
         // if
         if (empty($body)) {
             $errors->addError(lang('Body is required'), 'body');
         }
         // if
         $recipients = array();
         if (is_foreachable($recipient_ids)) {
             $recipients = Users::findByIds(array_unique($recipient_ids));
         }
         // if
         if (!is_foreachable($recipients)) {
             $errors->addError(lang('Please select recipients'), 'recipients');
         }
         // if
         if ($errors->hasErrors()) {
             $this->smarty->assign('errors', $errors);
             $this->render();
         }
         // if
         $mailer =& ApplicationMailer::mailer();
         $message = new Swift_Message($subject, $body, 'text/html', EMAIL_ENCODING, EMAIL_CHARSET);
         $recipients_list = new Swift_RecipientList();
         foreach ($recipients as $recipient) {
             $name = $recipient->getDisplayName();
             $email = $recipient->getEmail();
             if ($name == $email) {
                 $name = '';
             }
             // if
             $recipients_list->add($email, $name);
         }
         // foreach
         $name = $this->logged_user->getDisplayName();
         $email = $this->logged_user->getEmail();
         if ($name == $email) {
             $name = '';
         }
         // if
         if ($mailer->batchSend($message, $recipients_list, new Swift_Address($email, $name))) {
             flash_success('Email has been successfully sent');
         } else {
             flash_error('Failed to send email');
         }
         // if
         $this->redirectTo('admin_tools_mass_mailer');
     }
     // if
 }
예제 #25
0
 /**
  * Validate before save
  *
  * @param ValidationErrors $errors
  * @return null
  */
 function validate(&$errors)
 {
     if ($this->validatePresenceOf('email', 5)) {
         if (is_valid_email($this->getEmail())) {
             if (!$this->validateUniquenessOf('email')) {
                 $errors->addError(lang('Email address you provided is already in use'), 'email');
             }
             // if
         } else {
             $errors->addError(lang('Email value is not valid'), 'email');
         }
         // if
     } else {
         $errors->addError(lang('Email value is required'), 'email');
     }
     // if
     if ($this->isNew()) {
         if (strlen(trim($this->raw_password)) < 3) {
             $errors->addError(lang('Minimal password length is 3 characters'), 'password');
         }
         // if
     } else {
         if ($this->raw_password !== false && strlen(trim($this->raw_password)) < 3) {
             $errors->addError(lang('Minimal password length is 3 characters'), 'password');
         }
         // if
     }
     // if
     $company_id = $this->getCompanyId();
     if ($company_id) {
         $company = Companies::findById($company_id);
         if (!instance_of($company, 'Company')) {
             $errors->addError(lang('Selected company does not exist'), 'company_id');
         }
         // if
     } else {
         $errors->addError(lang('Please select company'), 'company_id');
     }
     // if
     if (!$this->validatePresenceOf('role_id')) {
         $errors->addError(lang('Role is required'), 'role_id');
     }
     // if
 }
 /**
  * Clone remote repository independent of any project.
  * @throws ValidationErrors
  */
 function clone_source_git_repository()
 {
     $logged_user = $this->logged_user;
     $user_id = $logged_user->getId();
     $web_user = GitoliteAdmin::get_web_user();
     $webuser_pub_key = GitoliteAdmin::get_web_user_key();
     /* echo $webuser_pub_key;
        print_r($webuser_pub_key);
        //die(); */
     $this->response->assign(array('form_action' => Router::assemble('clone_source_git_repository'), 'web_user' => $web_user, 'webuser_pub_key' => $webuser_pub_key));
     if ($this->request->isSubmitted()) {
         // check for form submission
         try {
             $repository_data = $this->request->post('repository');
             $repo_name = trim($repository_data["name"]);
             $repo_url = trim($this->request->post("remoteurl"));
             $errors = new ValidationErrors();
             $post_data = $this->request->post();
             if ($repo_name == "") {
                 $errors->addError('Please enter repository name', 'repo_name');
             }
             if ($repo_url == "") {
                 $errors->addError('Please enter repository URL', 'repo_name');
             }
             $dup_cnt = ProjectGitolite::check_remote_duplication($project_id, $repository_data, $repo_url);
             if (!$errors->hasErrors()) {
                 if (!preg_match("/^[A-Za-z0-9-]+\$/", $repo_name)) {
                     $errors->addError('Please enter valid repository name.', 'repo_name');
                 }
                 /* if(preg_match('|^[a-z]?:@[a-z0-9]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $url))
                    {
                    return ;
                    } */
                 if (strstr($repo_url, "http://") || strstr($repo_url, "https://")) {
                     $errors->addError('HTTP url not allowed to add remote repository', 'repo_url');
                 }
                 /* if(!strstr($repo_url,  "git://github.com/"))
                    {
                    $errors->addError('Please enter valid Git URL', 'repo_url');
                    } */
                 if (count($dup_cnt) == 0) {
                     $errors->addError('Problem occured while saving data, please try again.');
                 } elseif (is_array($dup_cnt) && count($dup_cnt) > 0) {
                     if ($dup_cnt[0]['dup_name_cnt'] > 0) {
                         $errors->addError('Repository with same name is already added');
                     }
                     if ($dup_cnt[1]['dup_name_cnt'] > 0) {
                         $errors->addError('Remote URL already cloned under this project.');
                     }
                 }
             }
             if ($errors->hasErrors()) {
                 throw $errors;
             }
             try {
                 DB::beginWork('Creating a new remote repository @ ' . __CLASS__);
                 $actual_git_repo_name = ProjectGitolite::get_actual_repo_name($repo_url);
                 if (!$actual_git_repo_name) {
                     $errors->addError('Invalid Git Repository.');
                     throw $errors;
                 }
                 // clone remote repo
                 // path with folder name which is created as same as repo name to avoid same git repo collision
                 $work_git_path = GIT_FILES_PATH . "/";
                 // path with folder name which is created after repo is cloned
                 $git_ext = strpos($actual_git_repo_name, ".git");
                 if ($git_ext) {
                     $actual_git_repo_name = substr($actual_git_repo_name, 0, -4);
                 }
                 $actual_repo_path = GIT_FILES_PATH . "/" . $repo_name . "/" . $actual_git_repo_name . "/";
                 $folder_append = "";
                 $chk_actual_name_exists_cnt = ProjectGitolite::check_actual_name_count($actual_git_repo_name);
                 if (is_array($chk_actual_name_exists_cnt) && isset($chk_actual_name_exists_cnt["actual_name_cnt"])) {
                     $cnt = $chk_actual_name_exists_cnt["actual_name_cnt"] > 0 ? $chk_actual_name_exists_cnt["actual_name_cnt"] + 1 : "";
                     $folder_append = $cnt != "" ? "-{$cnt}" : "";
                 } else {
                     $folder_append = "-1";
                 }
                 // if git repsitory name is same , we need to change the folder name while cloning the repository
                 $folder_name = $actual_git_repo_name . $folder_append;
                 $actual_repo_path = GIT_FILES_PATH . "/" . $folder_name . "/";
                 $return_status = GitoliteAdmin::clone_remote_repo($repo_url, $work_git_path, $folder_name);
                 if (!$return_status) {
                     $errors->addError('Problem occured while cloning repository.');
                     throw $errors;
                 }
                 $repository_path_url = array('repository_path_url' => $actual_repo_path);
                 //echo $work_git_path;
                 $repository_data = array_merge($repository_data, $repository_path_url);
                 $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_remote_repo_details($repo_fk, $user_id, $actual_repo_path, $repo_name, $repo_url, $actual_git_repo_name);
                     if ($repo_id) {
                         DB::commit('Repository created @ ' . __CLASS__);
                         //$out = $this->update_remote_repo($repo_fk);
                         $out = GitoliteAdmin::update_remote_repo($repo_fk);
                         $this->response->respondWithData($this->active_repository, array('as' => 'repository'));
                     } else {
                         @ProjectGitolite::remove_directory($work_git_path);
                         $errors->addError('Error while saving repository.');
                         throw $errors;
                     }
                 } else {
                     @ProjectGitolite::remove_directory($work_git_path);
                     $errors->addError('Error while saving repository.');
                     throw $errors;
                 }
             } 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);
         }
     }
 }
예제 #27
0
 /**
  * Validate before save
  *
  * @param ValidationErrors $errors
  * @return null
  */
 function validate(&$errors)
 {
     if (!$this->validateUniquenessOf('name')) {
         $errors->addError(lang('Language name needs to be unique'), 'name');
     }
     // if
 }
 /**
  * Reset users password
  *
  * @param void
  * @return null
  */
 function reset_password()
 {
     $user_id = $this->request->getId('user_id');
     $code = trim($this->request->get('code'));
     if (empty($user_id) || empty($code)) {
         $this->httpError(HTTP_ERR_INVALID_PROPERTIES);
     }
     // if
     $user = null;
     if ($user_id) {
         $user = Users::findById($user_id);
     }
     // if
     // Valid user and key
     if (!instance_of($user, 'User')) {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     // if
     if ($user->getPasswordResetKey() != $code) {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     // if
     // Not expired
     $reset_on = $user->getPasswordResetOn();
     if (instance_of($reset_on, 'DateTimeValue')) {
         if ($reset_on->getTimestamp() + 172800 < time()) {
             $this->httpError(HTTP_ERR_NOT_FOUND);
         }
         // if
     } else {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     // if
     $reset_data = $this->request->post('reset');
     $this->smarty->assign(array('reset_data' => $reset_data, 'user' => $user));
     if ($this->request->isSubmitted()) {
         $password = array_var($reset_data, 'password');
         $password_a = array_var($reset_data, 'password_a');
         $errors = new ValidationErrors();
         if (strlen_utf($password) < 3) {
             $errors->addError(lang('Minimal password length is 3 characters'), 'password');
         }
         // if
         if ($password != $password_a) {
             $errors->addError(lang('Passwords do not match'), 'passwords');
         }
         // if
         if ($errors->hasErrors()) {
             $this->smarty->assign('errors', $errors);
             $this->render();
         }
         // if
         $user->setPassword($password);
         $user->setPasswordResetKey(null);
         $user->setPasswordResetOn(null);
         $save = $user->save();
         if ($save && !is_error($save)) {
             $this->authentication->provider->logUserIn($user);
             flash_success('Welcome back :name', array('name' => $user->getDisplayName()));
             $this->redirectTo('dashboard');
         } else {
             $this->smarty->assign('errors', $errors);
         }
         // if
     }
     // if
 }
예제 #29
0
 /**
  * Validate before save
  *
  * @param ValidationErrors $errors
  * @return null
  */
 function validate(&$errors)
 {
     if ($this->validatePresenceOf('name')) {
         if (!$this->validateUniquenessOf('name')) {
             $errors->addError(lang('Company name needs to be unique'), 'name');
         }
         // if
     } else {
         $errors->addError(lang('Company name is required'), 'name');
     }
     // if
     if ($this->getIsOwner() && $this->getIsArchived()) {
         $errors->addError(lang("Owner company can't be archived"));
     }
     // if
 }
 /**
  * Show and process add to projects page
  *
  * @param void
  * @return null
  */
 function add_to_projects()
 {
     if ($this->active_user->isNew()) {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     // if
     if (!$this->logged_user->isProjectManager()) {
         $this->httpError(HTTP_ERR_FORBIDDEN);
     }
     // if
     $add_to_projects_data = $this->request->post('add_to_projects');
     $this->smarty->assign(array('add_to_projects_data' => $add_to_projects_data, 'exclude_project_ids' => Projects::findProjectIdsByUser($this->active_user)));
     if ($this->request->isSubmitted()) {
         $errors = new ValidationErrors();
         $projects = null;
         if (is_foreachable($add_to_projects_data['projects'])) {
             $projects = Projects::findByIds($add_to_projects_data['projects']);
         }
         // if
         if (!is_foreachable($projects)) {
             $errors->addError(lang('Please select projects'), 'projects');
         }
         // if
         if ($add_to_projects_data['role_id']) {
             $role = Roles::findById($add_to_projects_data['role_id']);
             $permissions = null;
             if (!instance_of($role, 'Role') || !($role->getType() == ROLE_TYPE_PROJECT)) {
                 $errors->addError(lang('Invalid project role'), 'project_permissions');
             }
             // if
         } else {
             $role = null;
             $permissions = array_var($add_to_projects_data, 'permissions');
         }
         // if
         if ($errors->hasErrors()) {
             $this->smarty->assign('errors', $errors);
         } else {
             $added = 0;
             foreach ($projects as $project) {
                 $add = $project->addUser($this->active_user, $role, $permissions);
                 if ($add && !is_error($add)) {
                     $added++;
                 }
                 // if
             }
             // foreach
             if ($added == 1) {
                 flash_success(':name has been added to 1 project', array('name' => $this->active_user->getDisplayName()));
             } else {
                 flash_success(':name has been added to :count projects', array('name' => $this->active_user->getDisplayName(), 'count' => $added));
             }
             // if
             $this->redirectToUrl($this->active_user->getViewUrl());
         }
         // if
     }
     // if
 }