Exemplo n.º 1
0
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
 public function executeInit(sfWebRequest $request)
 {
     //Check if kernel init went fine:
     $this->status = $this->getContext()->get('KernelStatus');
     $this->getContext()->getUser()->setAttribute('relativeUrlRoot', $request->getRelativeUrlRoot());
     //Add the log entry corresponding to the Kernel status:
     $log_ok = $this->getContext()->get('Kernel')->addLogIf(empty($this->status), array('info' => 'Application startup successful', 'error' => 'Application startup failed.'));
     //Check if error occured while logging:
     if (!$log_ok) {
         $this->status['log'] = 'Log files are unreachable, please check permissions on the log directory.';
     }
     //Edit the databases.yml file:
     ParametersConfiguration::editYaml();
     //Redirect to the localized homepage if everything went fine:
     $usersAuth = new usersAuth();
     /*Depending on the user Type (disconnected, admin, viewer), a redirection is done*/
     if ($usersAuth->isAdmin()) {
         $this->redirectIf(empty($this->status), '@localized_homepage');
     } else {
         if ($usersAuth->isViewer()) {
             $this->redirectIf(empty($this->status), '@localized_homepage');
         } else {
             $this->redirectIf(empty($this->status), '@authentification');
         }
     }
 }
Exemplo n.º 2
0
 public function executeIndex(sfWebRequest $request)
 {
     $this->moderators = Doctrine::getTable('Moderator')->createQuery('a')->orderBy('a.surname')->execute();
     ParametersConfiguration::setUserPrefix(sfContext::getInstance()->getUser()->getAttribute('login'));
     $this->defaultLength = ParametersConfiguration::getDefault('default_num_to_display');
     $this->userCulture = $this->getUser()->getCulture();
 }
 public function configure()
 {
     $this->disableLocalCSRFProtection();
     /*---------------------------------- WIDGETS CONFIGURATION ----------------------------------*/
     foreach ($this->getOption('users', array()) as $user_id) {
         $this->widgetSchema['computer_id_' . $user_id] = new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Computer'), 'add_empty' => false));
         $this->validatorSchema['computer_id_' . $user_id] = new sfValidatorDoctrineChoice(array('model' => $this->getRelatedModelName('Computer')));
         $this->setDefaults(array('computer_id_' . $user_id => ParametersConfiguration::getDefault('default_computer')));
     }
     $this->widgetSchema['unitary_price'] = new sfWidgetFormInputText();
     $act_price = Doctrine::getTable('ActPrice')->findOneByActIdAndActPublicCategoryId($this->getObject()->getImputation()->getActId(), $this->getOption('public_category'));
     if ($act_price['value'] == -1) {
         $this->widgetSchema->setDefault('unitary_price', 0);
     } else {
         $this->widgetSchema->setDefault('unitary_price', $act_price['value']);
     }
     /*---------------------------------- VALIDATORS CONFIGURATION ----------------------------------*/
     $this->validatorSchema['imputation_id']->addOption('required', false);
     $this->validatorSchema['computer_id']->setOption('required', true);
     $this->validatorSchema['unitary_price'] = new sfValidatorNumber();
     /*-------------------------------------------- LABELS ------------------------------------------*/
     $this->widgetSchema->setLabel('computer_id', 'Computer');
     /*--------------------------------------- FORMS EMBEDDING --------------------------------------*/
     /*Embed a imputation form:*/
     $subFormImputation = new ImputationForm($this->getObject()->getImputation(), array_merge($this->getOptions(), array('imputation_type' => ImputationDefaultValues::UNITARY_SERVICE_TYPE)));
     $this->embedForm('imputation', $subFormImputation);
 }
 /**
  * 
  * @param unknown_type $user_id
  * @param unknown_type $moderator_id
  */
 public function preConfigure($user_id, $moderator_id, $act_id, $act_public_category_id = null)
 {
     ParametersConfiguration::setUserPrefix(sfContext::getInstance()->getUser()->getAttribute('login'));
     //Get the user:
     $user = Doctrine::getTable('User')->findOneById($user_id);
     //Get the moderator:
     $moderator = Doctrine::getTable('Moderator')->findOneById($moderator_id);
     //Get the act:
     //Get the moderator:
     $act = Doctrine::getTable('Act')->findOneById($act_id);
     //Set the user for the object ImputationAccountTransaction
     $this->getImputation()->setUser($user);
     //If the parameter "follow moderator actions" have been checked: set the moderator for the object ImputationAccountTransaction
     if (ParametersConfiguration::getDefault('default_follow_moderator')) {
         $this->getImputation()->setModerator($moderator);
     } else {
         //Otherwise, set it to null:
         $this->getImputation()->setModeratorId(null);
     }
     //Set the act
     $this->getImputation()->setAct($act);
     //Set the date (today by default):
     $this->getImputation()->setDate(date('m/d/Y H:i'));
     //Set the room, building, method of payment and unity id:
     $this->getImputation()->setRoomId(ImputationDefaultValues::getDefaultValueByType(ImputationDefaultValues::DEFAULT_ROOM, ImputationDefaultValues::PURCHASE_TYPE));
     $this->getImputation()->setBuildingId(ImputationDefaultValues::getDefaultValueByType(ImputationDefaultValues::DEFAULT_BUILDING, ImputationDefaultValues::PURCHASE_TYPE));
     $this->getImputation()->setMethodOfPaymentId(ParametersConfiguration::getDefault('default_method_of_payment'));
     $this->getImputation()->setUnityId(ParametersConfiguration::getDefault('default_currency'));
     //Set the imputation type to 2:
     $this->getImputation()->setImputationType(ImputationDefaultValues::PURCHASE_TYPE);
 }
 public function setup()
 {
     //Get the buildings designation:
     $buildings = array(0 => '');
     $buildings_query = Doctrine_Query::create()->select('b.*')->from('Building b');
     $buildings_res = $buildings_query->fetchArray();
     foreach ($buildings_res as $building) {
         $buildings[$building['id']] = $building['designation'];
     }
     //Get the rooms designation:
     $rooms = array(0 => '');
     $rooms_query = Doctrine_Query::create()->select('r.designation')->from('Room r');
     $rooms_res = $rooms_query->fetchArray();
     foreach ($rooms_res as $room) {
         $rooms[$room['id']] = $room['designation'];
     }
     //Get the methods of payment designation:
     $methods_of_payment = array(0 => '');
     $methods_of_payment_query = Doctrine_Query::create()->select('m.designation')->from('ImputationMethodOfPayment m')->orderBy('m.sort_order');
     $methods_of_payment_res = $methods_of_payment_query->fetchArray();
     foreach ($methods_of_payment_res as $method_of_payment) {
         $methods_of_payment[$method_of_payment['id']] = $method_of_payment['designation'];
     }
     //Get the computers name:
     $computers = array(0 => '');
     $computers_query = Doctrine_Query::create()->select('c.name')->from('Computer c');
     $computers_res = $computers_query->fetchArray();
     foreach ($computers_res as $computer) {
         $computers[$computer['id']] = $computer['name'];
     }
     $unities = array(0 => '');
     $unities_query = Doctrine_Query::create()->select('u.*')->from('Unity u')->orderBy('u.sort_order');
     $unities_res = $unities_query->fetchArray();
     foreach ($unities_res as $unity) {
         if (!$unity['disabled']) {
             $unities[$unity['id']] = $unity['designation'];
         }
     }
     //Get the installed cultures passed as an option in the super class constructor:
     $languages = array_fill_keys($this->getOption('cultures', array('en')), null);
     $languages = ParametersConfiguration::formatLanguages($languages);
     //Fill the list of the choices for numbers of entries to display in a list:
     $numbers_to_display = array(10 => '10', 25 => '25', 50 => '50', 100 => '100');
     $agenda_time = array();
     for ($i = 0; $i < 24; $i++) {
         $agenda_time[$i] = $i;
     }
     /*----------------------------------WIDGETS----------------------------------------------*/
     $this->setWidgets(array('default_building' => new sfWidgetFormSelect(array('choices' => $buildings)), 'default_room' => new sfWidgetFormSelect(array('choices' => $rooms)), 'default_method_of_payment' => new sfWidgetFormSelect(array('choices' => $methods_of_payment)), 'default_computer' => new sfWidgetFormSelect(array('choices' => $computers)), 'default_num_to_display' => new sfWidgetFormSelect(array('choices' => $numbers_to_display)), 'default_follow_moderator' => new sfWidgetFormInputCheckbox(array(), array('value' => $this->getOption('follow'))), 'default_language' => new sfWidgetFormSelect(array('choices' => $languages)), 'default_currency' => new sfWidgetFormSelect(array('choices' => $unities)), 'def_mysql_port' => new sfWidgetFormInputText(), 'def_pgsql_port' => new sfWidgetFormInputText(), 'reservation_min_time' => new sfWidgetFormSelect(array('choices' => $agenda_time)), 'reservation_max_time' => new sfWidgetFormSelect(array('choices' => $agenda_time))));
     $this->widgetSchema->setLabels(array('default_building' => 'Building', 'default_room' => 'Room', 'default_method_of_payment' => 'Method of payment', 'default_computer' => 'Computer', 'default_num_to_display' => 'Number of entries to display', 'default_follow_moderator' => 'Follow administrator actions', 'default_language' => 'Language', 'default_currency' => 'Currency', 'def_mysql_port' => 'MySQL port', 'def_pgsql_port' => 'PostgreSQL port', 'reservation_min_time' => 'Beginning time', 'reservation_max_time' => 'End time'));
     /*-----------------------------------VALIDATORS-------------------------------------------*/
     $this->setValidators(array('default_building' => new sfValidatorInteger(array('min' => 0)), 'default_room' => new sfValidatorInteger(array('min' => 0)), 'default_method_of_payment' => new sfValidatorInteger(array('min' => 0)), 'default_computer' => new sfValidatorInteger(array('min' => 0)), 'default_num_to_display' => new sfValidatorInteger(array('min' => 0)), 'default_follow_moderator' => new sfValidatorBoolean(), 'default_language' => new sfValidatorString(array('max_length' => 2)), 'default_currency' => new sfValidatorInteger(array('min' => 0)), 'def_mysql_port' => new sfValidatorInteger(array('max' => 65535, 'min' => 0)), 'def_pgsql_port' => new sfValidatorInteger(array('max' => 65535, 'min' => 0)), 'reservation_min_time' => new sfValidatorInteger(array('min' => 0, 'max' => 23)), 'reservation_max_time' => new sfValidatorInteger(array('min' => 0, 'max' => 23))));
     $this->widgetSchema->setNameFormat('%s');
     $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);
 }
Exemplo n.º 6
0
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
 public function executeIndex(sfWebRequest $request)
 {
     $this->structure = Doctrine::getTable('Structure')->createQuery('a')->fetchOne();
     sfContext::getInstance()->getUser()->setAttribute('relativeUrlRoot', $request->getRelativeUrlRoot());
     if ($request->isMethod(sfRequest::POST)) {
         /*$context=sfContext::getInstance();*/
         $login = $this->getRequestParameter('login');
         $password = $this->getRequestParameter('password');
         $usersAuth = new usersAuth();
         $checked = $usersAuth->verifyAuth($login, $password);
         //if the authentification is done
         if ($checked == 1 || $checked == 2) {
             ParametersConfiguration::setUserPrefix(sfContext::getInstance()->getUser()->getAttribute('login'));
             $loginDisplay = ParametersConfiguration::getDefault('default_follow_moderator');
             /*According to the 'default_follow_moderator' parameter, the login will appear in logs or not*/
             if ($loginDisplay == 1) {
                 $this->getContext()->get('Kernel')->addLog("info", "Authentification success for the login \"" . $login . "\".");
             } else {
                 $this->getContext()->get('Kernel')->addLog("info", "Authentification success.");
             }
             //Get the preferred culture of the user, based on those which are installed:
             $culture = ParametersConfiguration::getDefault('default_language');
             $this->getUser()->setCulture($culture);
             $request->setParameter('sf_culture', $culture);
             $this->redirect('@localized_homepage');
         } else {
             if ($checked === 0) {
                 // this delay complicates a brute force attack
                 sleep(1);
                 $this->getUser()->setFlash('error', 'Login or password incorrect. Please try again.', true);
                 $this->getContext()->get('Kernel')->addLog("error", "Authentification denied for the login \"" . $login . "\".");
             } else {
                 if ($checked === -2) {
                     $this->getUser()->setFlash('error', 'Login and password are correct but your account is locked.', true);
                     $this->getContext()->get('Kernel')->addLog("error", "Authentification denied for the login \"" . $login . "\". Account is locked.");
                 } else {
                     //The error message is copied in the error log
                     $this->getContext()->get('Kernel')->addLog("error", "Connection to the database failed:\"" . $checked . "\".");
                     $this->getUser()->setFlash('error', 'Impossible authentification. Check the connection to the database.', true);
                 }
             }
         }
     } else {
         $this->login = null;
         $this->password = null;
     }
 }
 /**
  * 
  * @param integer $user_id
  * @param integer $moderator_id
  * @param integer $act_id
  * @param integer $act_public_category_id
  */
 public function preConfigure($user_id, $moderator_id, $act_id, $act_public_category_id = null)
 {
     ParametersConfiguration::setUserPrefix(sfContext::getInstance()->getUser()->getAttribute('login'));
     //Get the user:
     $user = Doctrine::getTable('User')->findOneById($user_id);
     //Get the moderator:
     $moderator = Doctrine::getTable('Moderator')->findOneById($moderator_id);
     //Get the act:
     //Get the moderator:
     $act = Doctrine::getTable('Act')->findOneById($act_id);
     //Set the user
     $this->getImputation()->setUser($user);
     //If the parameter "follow moderator actions" have been checked: set the moderator for the object ImputationAccountTransaction
     if (ParametersConfiguration::getDefault('default_follow_moderator')) {
         $this->getImputation()->setModerator($moderator);
     } else {
         //Otherwise, set it to null:
         $this->getImputation()->setModeratorId(null);
     }
     //Set the act
     $this->getImputation()->setAct($act);
     //Set the imputation 'total' based on the act_price:
     $act_price = Doctrine::getTable('ActPrice')->findOneByActIdAndActPublicCategoryId($act_id, $act_public_category_id);
     if ($act_price['value'] == -1) {
         $this->getImputation()->setTotal(0);
     } else {
         $this->getImputation()->setTotal($act_price['value']);
     }
     //Set the 'number of unities' by default to 1:
     $this->setNumberOfUnities(1);
     //Set the date (today by default):
     $this->getImputation()->setDate(date('m/d/Y H:i'));
     //Set the end_time (current hour by default):
     $this->setEndTime(date('H:i'));
     //Set the beginning time:
     $this->setBeginningTimeConf($act['duration']);
     //Set the room, building, computer, method of payment and unity id:
     $this->getImputation()->setRoomId(ImputationDefaultValues::getDefaultValueByType(ImputationDefaultValues::DEFAULT_ROOM, ImputationDefaultValues::UNITARY_SERVICE_TYPE));
     $this->getImputation()->setBuildingId(ImputationDefaultValues::getDefaultValueByType(ImputationDefaultValues::DEFAULT_BUILDING, ImputationDefaultValues::UNITARY_SERVICE_TYPE));
     $this->setComputerId(ParametersConfiguration::getDefault('default_computer'));
     $this->getImputation()->setMethodOfPaymentId(ParametersConfiguration::getDefault('default_method_of_payment'));
     $this->getImputation()->setUnityId(ParametersConfiguration::getDefault('default_currency'));
     //Set the imputation type to 2:
     $this->getImputation()->setImputationType(ImputationDefaultValues::UNITARY_SERVICE_TYPE);
 }
 /**
  * 
  * @param integer $user_id
  * @param integer $moderator_id
  * @param integer $act_id
  * @param integer $act_public_category_id
  */
 public function preConfigure($user_id, $moderator_id, $act_id, $act_public_category_id = null)
 {
     ParametersConfiguration::setUserPrefix(sfContext::getInstance()->getUser()->getAttribute('login'));
     //Get the user:
     $user = Doctrine::getTable('User')->findOneById($user_id);
     //Get the moderator:
     $moderator = Doctrine::getTable('Moderator')->findOneById($moderator_id);
     //Get the act:
     //Get the moderator:
     $act = Doctrine::getTable('Act')->findOneById($act_id);
     //Set the user
     $this->getImputation()->setUser($user);
     //If the parameter "follow moderator actions" have been checked: set the moderator for the object ImputationAccountTransaction
     if (ParametersConfiguration::getDefault('default_follow_moderator')) {
         $this->getImputation()->setModerator($moderator);
     } else {
         //Otherwise, set it to null:
         $this->getImputation()->setModeratorId(null);
     }
     //Set the act
     $this->getImputation()->setAct($act);
     //Set the default initial value based on the quantity of the act:
     $this->setInitialValue($this->getImputation()->getAct()->getQuantity());
     //Set the imputation 'total' based on the act_price:
     $act_price = Doctrine::getTable('ActPrice')->findOneByActIdAndActPublicCategoryId($act_id, $act_public_category_id);
     if ($act_price['value'] == -1) {
         if ($this->getImputation()->getAct()->getMonetaryAccount()) {
             $this->getImputation()->setTotal($this->getImputation()->getAct()->getQuantity());
         } else {
             $this->getImputation()->setTotal(0);
         }
     } else {
         $this->getImputation()->setTotal($act_price['value']);
     }
     //Set the date (today by default):
     $this->getImputation()->setDate(date('m/d/Y H:i'));
     //Set the room, building, method of payment and unity id:
     $this->getImputation()->setRoomId(ImputationDefaultValues::getDefaultValueByType(ImputationDefaultValues::DEFAULT_ROOM, ImputationDefaultValues::COUNTABLE_SERVICE_TYPE));
     $this->getImputation()->setBuildingId(ImputationDefaultValues::getDefaultValueByType(ImputationDefaultValues::DEFAULT_BUILDING, ImputationDefaultValues::COUNTABLE_SERVICE_TYPE));
     $this->getImputation()->setMethodOfPaymentId(ParametersConfiguration::getDefault('default_method_of_payment'));
     $this->getImputation()->setUnityId($act->getUnityId());
     //Set the imputation type to 3:
     $this->getImputation()->setImputationType(ImputationDefaultValues::COUNTABLE_SERVICE_TYPE);
 }
Exemplo n.º 9
0
 public function executeSystemParameters(sfWebRequest $request)
 {
     $error = 0;
     $this->forward404Unless($request->isMethod(sfRequest::POST));
     //If the HTTP method is "post", get the values entered by the user:
     $this->values = array('ip_address' => $this->getRequestParameter('ip_address'), 'srv_port' => $this->getRequestParameter('srv_port'), 'dbms' => $this->getRequestParameter('dbms') + 1, 'db_name' => $this->getRequestParameter('db_name'), 'db_user_name' => $this->getRequestParameter('db_user_name'), 'db_password' => $this->getRequestParameter('db_password'), '_csrf_token' => $this->getRequestParameter('_csrf_token'));
     //Build the form with theses values:
     $form = new SystemParametersForm($this->values);
     //Execute the validators of this form:
     $form->bind($this->values);
     //If everything is fine:
     if ($form->isValid()) {
         //Insert the new values in the xml configuration file:*/
         ParametersConfiguration::setBddParams($this->values);
         ParametersConfiguration::editYaml();
         sfToolkit::clearGlob(sfConfig::get('sf_cache_dir') . '/install/*');
         $this->redirect('firstBoot/stepTwo');
     } else {
         $this->form = $form;
         $this->setTemplate("stepOne");
     }
 }
Exemplo n.º 10
0
                week :     "<?php 
echo __('week');
?>
",
                day :      "<?php 
echo __('day');
?>
"
            },
            minTime: "<?php 
$time = ParametersConfiguration::getDefault('reservation_min_time');
echo $time ? $time : 8;
?>
",
            maxTime: "<?php 
$time = ParametersConfiguration::getDefault('reservation_max_time');
echo $time ? $time : 18;
?>
",
            allDaySlot: false,
            axisFormat: "<?php 
echo __('HH:mm{ - HH:mm} ');
?>
",
            header: {
                left: 'prev,next today',
                center: 'title',
                right: 'month,agendaWeek,agendaDay'
            },
            aspectRatio: 2,
            events : {
Exemplo n.º 11
0
 public function configure()
 {
     /*---------------------------------- WIDGETS CONFIGURATION ----------------------------------*/
     foreach ($this->getOption('users', array()) as $user_id) {
         $this->widgetSchema['method_of_payment_id_' . $user_id] = new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('ImputationMethodOfPayment'), 'add_empty' => false));
         $this->validatorSchema['method_of_payment_id_' . $user_id] = new sfValidatorDoctrineChoice(array('model' => $this->getRelatedModelName('ImputationMethodOfPayment')));
         $this->setDefaults(array('method_of_payment_id_' . $user_id => ParametersConfiguration::getDefault('default_method_of_payment')));
     }
     foreach ($this->getOption('users', array()) as $user_id) {
         $this->widgetSchema['user_id_' . $user_id] = new sfWidgetFormInputText();
         $this->validatorSchema['user_id_' . $user_id] = new sfValidatorDoctrineChoice(array('model' => $this->getRelatedModelName('User'), 'required' => false));
         $this->widgetSchema['user_id_' . $user_id]->setAttribute('value', $user_id);
         $this->widgetSchema['user_id_' . $user_id]->setAttribute('type', 'hidden');
     }
     $this->widgetSchema['user_id'] = new sfWidgetFormInputHidden(array(), array('readonly' => 'readonly'));
     $this->widgetSchema['act_id'] = new sfWidgetFormInputHidden(array(), array('readonly' => 'readonly'));
     $this->widgetSchema['moderator_id'] = new sfWidgetFormInputHidden(array(), array('readonly' => 'readonly'));
     $this->widgetSchema['imputation_type'] = new sfWidgetFormInputHidden(array(), array('readonly' => 'readonly'));
     $this->widgetSchema['comment'] = new sfWidgetFormTextarea();
     $this->widgetSchema['date'] = new sfWidgetFormI18nDateTime(array('culture' => $this->getOption('culture')));
     $this->widgetSchema['total']->setAttribute('size', 5);
     /*---------------------------------- VALIDATORS CONFIGURATION ----------------------------------*/
     $this->validatorSchema['date']->setOption('required', true);
     $this->validatorSchema['date']->setMessage('invalid', 'The date/time format is invalid.');
     $this->validatorSchema['user_id']->setOption('required', true);
     $this->validatorSchema['total']->setOption('required', true);
     $this->validatorSchema['account_id']->setOption('required', true);
     if ($this->getOption('imputation_type') != ImputationDefaultValues::ACCOUNT_TRANSACTION_TYPE) {
         $this->validatorSchema['room_id']->setOption('required', true);
         $this->validatorSchema['building_id']->setOption('required', true);
         $this->validatorSchema['act_id']->setOption('required', true);
     }
     /*--------------- MODIFICATION OF THE 'TOTAL' WIDGET IN 2 PARTICULAR CASE:-----------------*/
     if ($this->getOption('imputation_type') == ImputationDefaultValues::COUNTABLE_SERVICE_TYPE || $this->getOption('imputation_type') == ImputationDefaultValues::SUBSCRIPTION_TYPE) {
         $this->widgetSchema->setLabel('total', 'Price');
     }
     /*--------------------- MODIFICATION OF THE 'UNITY_ID' WIDGET IN 4 CASES:-------------------*/
     if ($this->getOption('imputation_type') != ImputationDefaultValues::COUNTABLE_SERVICE_TYPE) {
         $this->widgetSchema['unity_id'] = new sfWidgetFormInputHidden();
     }
     /*------------------------- ACCOUNTS WHOSE BELONGS TO THE USERS:----------------------------*/
     $userAccounts = Doctrine::getTable('AccountUser')->findByUserId($this->getObject()->getUser()->getId());
     $user_account_designations = array(0 => '');
     foreach ($userAccounts as $userAccount) {
         if ($this->getOption('imputation_type') == ImputationDefaultValues::ACCOUNT_TRANSACTION_TYPE) {
             $user_account_designations[$userAccount->getAccount()->getId()] = $userAccount->getAccount()->getAct()->getDesignation();
         } else {
             if ($userAccount->getAccount()->getMonetaryAccount() == 1) {
                 $user_account_designations[$userAccount->getAccount()->getId()] = $userAccount->getAccount()->getAct()->getDesignation();
             }
         }
     }
     $this->widgetSchema['account_id'] = new sfWidgetFormChoice(array('choices' => $user_account_designations, 'multiple' => false, 'expanded' => false));
     $this->validatorSchema['account_id'] = new sfValidatorChoice(array('choices' => array_keys($user_account_designations)), array('invalid' => 'the account id is invalid'));
     foreach ($this->getOption('users', array()) as $user_id) {
         $userAccounts = Doctrine::getTable('AccountUser')->findByUserId($user_id);
         $user_account_designations = array(0 => '');
         foreach ($userAccounts as $userAccount) {
             if ($this->getOption('imputation_type') == ImputationDefaultValues::ACCOUNT_TRANSACTION_TYPE) {
                 $user_account_designations[$userAccount->getAccount()->getId()] = $userAccount->getAccount()->getAct()->getDesignation();
             } else {
                 if ($userAccount->getAccount()->getMonetaryAccount() == 1) {
                     $user_account_designations[$userAccount->getAccount()->getId()] = $userAccount->getAccount()->getAct()->getDesignation();
                 }
             }
         }
         $this->widgetSchema['account_id_' . $user_id] = new sfWidgetFormChoice(array('choices' => $user_account_designations, 'multiple' => false, 'expanded' => false));
         $this->validatorSchema['account_id_' . $user_id] = new sfValidatorChoice(array('choices' => array_keys($user_account_designations)), array('invalid' => 'the account id is invalid'));
     }
     /*--------------------------------- CORRESPONDING ACT:------------------------------------*/
     if ($this->getOption('imputation_type') != ImputationDefaultValues::ACCOUNT_TRANSACTION_TYPE) {
         //Set the default act id:
         $this->widgetSchema->setDefault('act_id', $this->getObject()->getAct()->getId());
     }
     /*------------------------------------------ LABELS --------------------------------------------*/
     $this->widgetSchema->setLabel('date', 'Date and Time');
     $this->widgetSchema->setLabel('moderator_id', 'Animator');
     $this->widgetSchema->setLabel('account_id', 'Concerned Account');
     if ($this->getOption('imputation_type') == ImputationDefaultValues::ACCOUNT_TRANSACTION_TYPE) {
         $this->widgetSchema->setLabel('method_of_payment_id', 'Paid by');
     } else {
         $this->widgetSchema->setLabel('method_of_payment_id', 'Pay by');
     }
 }
 /**
  * 
  * @param integer $type
  */
 private static function getBuildingByType($type)
 {
     switch ($type) {
         case self::ACCOUNT_TRANSACTION_TYPE:
             return null;
             break;
         case self::PURCHASE_TYPE:
             return ParametersConfiguration::getDefault(self::DEFAULT_BUILDING);
             break;
         case self::COUNTABLE_SERVICE_TYPE:
             return ParametersConfiguration::getDefault(self::DEFAULT_BUILDING);
             break;
         case self::UNITARY_SERVICE_TYPE:
             return ParametersConfiguration::getDefault(self::DEFAULT_BUILDING);
             break;
         case self::SUBSCRIPTION_TYPE:
             return ParametersConfiguration::getDefault(self::DEFAULT_BUILDING);
             break;
         default:
             return null;
     }
 }
 /**
  * 
  * @param $parameters
  */
 public static function buildAndSaveTransactionFrom($parameters)
 {
     /* --- Duplicate the parameters: --- */
     $parameters_account_transaction = $parameters;
     /* --- Change the parameters: --- */
     /* --- Unset those who do not correspond to an account transaction: --- */
     $parameters_account_transaction = ImputationAccountTransaction::unsetFieldsByType($parameters_account_transaction, $parameters_account_transaction['imputation']['imputation_type']);
     /* --- Add the missing ones: --- */
     $parameters_account_transaction['sum'] = $parameters_account_transaction['imputation']['total'];
     /* --- Modify those who need to be modified --- */
     $parameters_account_transaction['imputation']['imputation_type'] = ImputationDefaultValues::ACCOUNT_TRANSACTION_TYPE;
     $parameters_account_transaction['imputation']['total'] = -$parameters_account_transaction['imputation']['total'];
     /* --- Create a form of type 'account transaction': --- */
     $transaction = new ImputationAccountTransaction();
     $transaction->getImputation()->setUserId($parameters_account_transaction['imputation']['user_id']);
     $form_account_transaction = new ImputationAccountTransactionForm($transaction, array('culture' => ParametersConfiguration::getDefault('default_language')));
     //Bind the form to the new parameters:
     $form_account_transaction->bind($parameters_account_transaction);
     //Save it if it's valid:
     if ($form_account_transaction->isValid() && $parameters['imputation']['account_id'] != 0) {
         /* --- Decrement the corresponding account: --- */
         $account = Doctrine::getTable('Account')->find($parameters['imputation']['account_id']);
         $account->setValue($account->getValue() - $parameters['imputation']['total']);
         $account->save();
         $form_account_transaction->save();
         return true;
     } else {
         return false;
     }
 }
			
			if($(this).val() == "<?php 
echo ImputationDefaultValues::getAccountMethodId();
?>
"){
				$("#imputation_account_transaction_account_to_pay_id").css("visibility","visible");
			}else{
				$("#imputation_account_transaction_account_to_pay_id").css("visibility","hidden");
			}
			
		});

		$("#imputation_account_transaction_imputation_method_of_payment_id").ready(function(){

			if("<?php 
echo ParametersConfiguration::getDefault('default_method_of_payment');
?>
" == "<?php 
echo ImputationDefaultValues::getAccountMethodId();
?>
"){
				$("#imputation_account_transaction_account_to_pay_id").css("visibility","visible");
			}else{
				$("#imputation_account_transaction_account_to_pay_id").css("visibility","hidden");
			}
			
		});

		$("#imputation_account_transaction_imputation_total").focus(function(){
			changeTotal();
		});
Exemplo n.º 15
0
 public function executeAjaxImputationInfo(sfWebRequest $request)
 {
     $accountTransaction = null;
     $purchase = null;
     $countableService = null;
     $unitaryService = null;
     $subscription = null;
     $computer = null;
     $imputationId = $request->getParameter('id');
     $imputation = Doctrine::getTable('Imputation')->findOneById($imputationId);
     switch ($imputation->getImputationType()) {
         case ImputationDefaultValues::ACCOUNT_TRANSACTION_TYPE:
             $accountTransaction = Doctrine::getTable('ImputationAccountTransaction')->findOneByImputationId($imputationId);
             $imputationType = "Account transaction";
             break;
         case ImputationDefaultValues::PURCHASE_TYPE:
             $purchase = Doctrine::getTable('ImputationPurchase')->findOneByImputationId($imputationId);
             $imputationType = "Purchase";
             break;
         case ImputationDefaultValues::COUNTABLE_SERVICE_TYPE:
             $countableService = Doctrine::getTable('ImputationCountableService')->findOneByImputationId($imputationId);
             $imputationType = "Countable service";
             break;
         case ImputationDefaultValues::UNITARY_SERVICE_TYPE:
             $unitaryService = Doctrine::getTable('ImputationUnitaryService')->findOneByImputationId($imputationId);
             $imputationType = "Unitary service";
             $computer = Doctrine::getTable('Computer')->findOneById($unitaryService['computer_id'])->getName();
             break;
         case ImputationDefaultValues::SUBSCRIPTION_TYPE:
             $subscription = Doctrine::getTable('ImputationSubscription')->findOneByImputationId($imputationId);
             $imputationType = "Subscription";
             break;
     }
     ParametersConfiguration::setUserPrefix(sfContext::getInstance()->getUser()->getAttribute('login'));
     $this->defaultCurrency = Doctrine::getTable('Unity')->findOneById(ParametersConfiguration::getDefault('default_currency'))->getShortenedDesignation();
     $this->accountTransaction = $accountTransaction;
     $this->purchase = $purchase;
     $this->countableService = $countableService;
     $this->unitaryService = $unitaryService;
     $this->subscription = $subscription;
     $this->imputation = $imputation;
     $this->imputationType = $imputationType;
     $this->computer = $computer;
     $this->setTemplate('imputationInfo', 'use');
 }
Exemplo n.º 16
0
 /**
  * Diplays the current values for the selected predefined multiple service
  * 
  * @param sfWebRequest $request
  * @param sfForm $form
  */
 public function executeEditMultipleService(sfWebRequest $request)
 {
     $this->forward404Unless($multipleService = Doctrine::getTable('Act')->find(array($request->getParameter('id'))), sprintf('Object purchase does not exist (%s).', $request->getParameter('id')));
     if ($multipleService['monetary_account'] == "0") {
         $monetaryAccount = null;
     } else {
         $monetaryAccount = 1;
     }
     $this->values = array('designation' => $multipleService['designation'], 'shortened_designation' => $multipleService['shortened_designation'], 'monetary_account' => $monetaryAccount, 'quantity' => $multipleService['quantity'], 'unity_id' => $multipleService['unity_id'], 'comment' => $multipleService['comment'], 'act_type_id' => $multipleService['act_type_id']);
     $this->multipleServiceId = $request->getParameter('id');
     //Used for the redirection
     if ($request->getParameter('index')) {
         $this->index = 1;
     } else {
         $this->index = 0;
     }
     $this->form = new MultipleServiceForm($this->values);
     $this->form->setWidget('unity_id', new sfWidgetFormInputHidden());
     if (!$multipleService['monetary_account']) {
         $this->unity = Doctrine::getTable('Unity')->findOneById($multipleService['unity_id']);
     } else {
         ParametersConfiguration::setUserPrefix(sfContext::getInstance()->getUser()->getAttribute('login'));
         $defaultCurrencyId = ParametersConfiguration::getDefault('default_currency');
         $this->unity = Doctrine::getTable('Unity')->findOneById($defaultCurrencyId)->getShortenedDesignation();
     }
     $this->form->getWidget('designation')->setAttribute('readonly', 'readonly');
     $this->form->getWidget('monetary_account')->setAttribute('readonly', 'readonly');
     $this->form->getWidget('shortened_designation')->setAttribute('readonly', 'readonly');
     $this->form->getWidget('quantity')->setAttribute('readonly', 'readonly');
 }
 public static function setUserPrefix($prefix)
 {
     self::$USER_CONFIG_PREFIX = $prefix;
 }
Exemplo n.º 18
0
 /**
  * Processes the deletion of a computer.
  * @param sfWebRequest $request
  */
 public function executeDeleteComputer(sfWebRequest $request)
 {
     ParametersConfiguration::setUserPrefix(sfContext::getInstance()->getUser()->getAttribute('login'));
     $defaultComputer = ParametersConfiguration::getDefault('default_computer');
     /*If this computer was the default computer, we set the parameter 'default_computer' to zero.*/
     if ($defaultComputer == $request->getParameter('id')) {
         ParametersConfiguration::setDefault('default_computer', 0);
     }
     Doctrine_Query::create()->delete('Computer c')->where('c.id = ?', $request->getParameter('id'))->execute();
     $this->getUser()->setFlash('notice', 'The computer has been deleted.');
     $this->redirect('struct/index#computers');
 }
Exemplo n.º 19
0
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
 public function executeIndex(sfWebRequest $request)
 {
     //We check if there is modules which have not been activated:
     if ($this->getContext()->get('Kernel')->getUnsatisfiedDependencies()) {
         $this->getUser()->setFlash('error', 'Some modules are not activated because dependencies are missing. Please go to the configuration menu to correct theses issues.', false);
     }
     // -----------------------------------------------------------------------------------------------------------
     // KYXAR 0006 - 30/06/2011
     // Modification des libellés du nombre d'abonnements valides sur le tableau de bord
     $todayDate = strftime("%Y%m%d");
     // KYXAR 0006 - 30/06/2011
     // -----------------------------------------------------------------------------------------------------------
     $beginningDate = strftime("%Y%m%d", mktime(0, 0, 0, date("m"), 1, date("Y")));
     $endDate = strftime("%Y%m%d", mktime(0, 0, 0, date("m") + 1, 0, date("Y")));
     $firstDayOfNextMonth = strftime("%Y%m%d", mktime(0, 0, 0, date("m") + 1, 1, date("Y")));
     $numberOfValidSubscriptionsBeginning = 0;
     $numberOfValidSubscriptionsEnd = 0;
     $numberOfUsesPerCategory = array();
     $numberOfUses = 0;
     $totalDuration = 0;
     /*We get the public categories*/
     $publicCategories = Doctrine_Query::create()->select('a.*')->from('ActPublicCategory a')->orderBy('a.sort_order')->execute();
     /*We count the number of visits*/
     $numberVisits = Doctrine_Query::create()->from('Imputation i')->where('i.date >= ?', $beginningDate)->addWhere('i.date < ?', $firstDayOfNextMonth)->addWhere('i.imputation_type <> ?', 1)->count();
     /*We count the number of unique visitors*/
     $numberOfUniqueVisitors = Doctrine_Query::create()->from('Imputation i')->where('i.date >= ?', $beginningDate)->addWhere('i.date < ?', $firstDayOfNextMonth)->groupBy('i.user_id')->count();
     $numberOfRegularVisitors = Doctrine_Query::create()->from('Imputation i')->where('i.date >= ?', $beginningDate)->addWhere('i.date < ?', $firstDayOfNextMonth)->groupBy('i.user_id, i.user_id HAVING COUNT(*)>1')->count();
     /*We count the total of the checkout*/
     $checkoutTotal = Doctrine_Query::create()->select('sum(i.total)')->from('Imputation i')->where('i.date >= ?', $beginningDate)->addWhere('i.date < ?', $firstDayOfNextMonth)->fetchArray();
     /*We get all the subscriptions*/
     $subscriptions = Doctrine_Query::create()->select('i.*')->from('Imputation i')->where('i.imputation_type = ?', "5")->execute();
     /*For each subscription, we compare its end date to the beginning date and the end date*/
     foreach ($subscriptions as $subscription) {
         $subscriptionFinalDateQuery = Doctrine::getTable('ImputationSubscription')->findOneByImputationId($subscription->getId());
         // -----------------------------------------------------------------------------------------------------------
         // KYXAR 0005 - 30/06/2011
         // Correction du nombre d'abonnements valides
         $beginOfSubscription = strtotime($subscription->getDate());
         $endOfSubscription = strtotime($subscriptionFinalDateQuery->getFinalDate());
         if ($beginOfSubscription <= strtotime($todayDate) && $endOfSubscription >= strtotime($todayDate)) {
             $numberOfValidSubscriptionsBeginning++;
         }
         if ($beginOfSubscription <= strtotime($endDate) && $endOfSubscription >= strtotime($endDate)) {
             $numberOfValidSubscriptionsEnd++;
         }
         // FIN KYXAR 0005 - 30/06/2011
         // -----------------------------------------------------------------------------------------------------------
     }
     /*We get all the uses (expected the transaction on an account uses*/
     $uses = Doctrine_Query::create()->select('i.*')->from('Imputation i')->where('i.date >= ?', $beginningDate)->addWhere('i.date < ?', $firstDayOfNextMonth)->addWhere('i.imputation_type <> ?', 1)->execute();
     foreach ($publicCategories as $publicCategory) {
         $numberOfUsesPerCategory[$publicCategory->getId()] = 0;
         $timePerCategory[$publicCategory->getId()] = 0;
     }
     $numberOfUsesPerCategory[0] = 0;
     $timePerCategory[0] = 0;
     foreach ($uses as $use) {
         $numberOfUses++;
         if ($use->getUserId() != null) {
             $user = Doctrine::getTable('User')->findOneById($use->getUserId());
             if ($user->getActPublicCategoryId() != null) {
                 $numberOfUsesPerCategory[$user->getActPublicCategoryId()]++;
             } else {
                 $numberOfUsesPerCategory[0]++;
             }
         } else {
             $numberOfUsesPerCategory[0]++;
         }
     }
     /*We get all the unitary services (services with a time)*/
     $unitaryServices = Doctrine_Query::create()->select('i.*')->from('Imputation i')->where('i.imputation_type = ?', "4")->addWhere('i.date >= ?', $beginningDate)->addWhere('i.date < ?', $firstDayOfNextMonth)->execute();
     foreach ($unitaryServices as $unitaryService) {
         $imputationUnitaryService = Doctrine::getTable('ImputationUnitaryService')->findOneByImputationId($unitaryService->getId());
         $beginningTime = $imputationUnitaryService->getBeginningTime();
         $endTime = $imputationUnitaryService->getEndTime();
         $duration = round((strtotime($endTime) - strtotime($beginningTime)) / 3600, 1);
         if ($unitaryService->getUserId() != null) {
             $user = Doctrine::getTable('User')->findOneById($unitaryService->getUserId());
             if ($user->getActPublicCategoryId() != null) {
                 $timePerCategory[$user->getActPublicCategoryId()] += $duration;
             } else {
                 $timePerCategory[0] += $duration;
             }
         } else {
             $timePerCategory[0] += $duration;
         }
         $totalDuration += $duration;
     }
     /*Send to the template*/
     $this->beginningDate = $beginningDate;
     $this->endDate = $endDate;
     $this->numberOfVisits = $numberVisits;
     $this->numberOfUniqueVisitors = $numberOfUniqueVisitors;
     $this->numberOfRegularVisitors = $numberOfRegularVisitors;
     $this->checkoutTotal = round($checkoutTotal[0]['sum'], 2);
     $this->numberOfValidSubscriptionsBeginning = $numberOfValidSubscriptionsBeginning;
     $this->numberOfValidSubscriptionsEnd = $numberOfValidSubscriptionsEnd;
     $this->numberOfUsesPerCategory = $numberOfUsesPerCategory;
     $this->publicCategories = $publicCategories;
     $this->numberOfUses = $numberOfUses;
     $this->totalDuration = $totalDuration;
     $this->timePerCategory = $timePerCategory;
     ParametersConfiguration::setUserPrefix(sfContext::getInstance()->getUser()->getAttribute('login'));
     $defaultCurrencyId = ParametersConfiguration::getDefault('default_currency');
     $this->defaultCurrency = Doctrine::getTable('Unity')->findOneById($defaultCurrencyId)->getDesignation();
 }
Exemplo n.º 20
0
 public function executeUpdateActPrices(sfWebRequest $request)
 {
     $acts = Doctrine::getTable('Act')->createQuery()->select('a.*')->from('Act a')->where('a.disabled <> 1')->execute();
     $publicCategories = Doctrine::getTable('ActPublicCategory')->createQuery()->select('ap.*')->from('ActPublicCategory ap')->orderBy('ap.sort_order')->execute();
     $noError = 1;
     $errorArray = array();
     //We get the modified cells
     $modifiedCellsRequest = $request->getParameter('modifiedCells');
     $modifiedCells = explode(",", $modifiedCellsRequest);
     //If some cells have been modified
     if ($modifiedCellsRequest != null) {
         foreach ($modifiedCells as $modifiedCell) {
             $exploded = explode("_", $modifiedCell);
             $actId = $exploded[1];
             $actPublicCategoryId = $exploded[2];
             $newPrice = $request->getParameter('price_' . $actId . '_' . $actPublicCategoryId);
             $newPrice = strtr($newPrice, ",", ".");
             $convert = array(" " => "");
             $newPrice = strtr($newPrice, $convert);
             $correctInsert = 0;
             if (is_numeric($newPrice)) {
                 $priceToInsert = $newPrice;
                 $correctInsert = 1;
             } else {
                 if (!strcmp($newPrice, "")) {
                     $priceToInsert = -1;
                     $correctInsert = 1;
                 } else {
                     $this->getUser()->setFlash('error', 'You made a mistake on one or several price(s). If you have any problem, click on the Help button.', false);
                     $noError = 0;
                     $errorArray[$actId][$actPublicCategoryId] = $newPrice;
                 }
             }
             if ($correctInsert) {
                 $updatedActPrice = Doctrine::getTable('ActPrice')->findOneByActIdAndActPublicCategoryId($actId, $actPublicCategoryId);
                 $updatedActPrice->setValue($priceToInsert);
                 $updatedActPrice->save();
             }
         }
         if ($noError) {
             $this->getUser()->setFlash('notice', 'The prices have been updated.', false);
         }
     }
     $actPrices_query = Doctrine_Query::create()->select('a.*')->from('ActPrice a');
     $actPrices_res = $actPrices_query->fetchArray();
     $actPrices = array();
     foreach ($actPrices_res as $price) {
         $actPrices[$price['act_id']][$price['act_public_category_id']] = $price['value'];
     }
     /*Redirect*/
     ParametersConfiguration::setUserPrefix(sfContext::getInstance()->getUser()->getAttribute('login'));
     $defaultCurrencyId = ParametersConfiguration::getDefault('default_currency');
     $this->defaultCurrency = Doctrine::getTable('Unity')->findOneById($defaultCurrencyId)->getDesignation();
     $this->price = $actPrices;
     $this->acts = $acts;
     $this->publicCategories = $publicCategories;
     $this->errorArray = $errorArray;
     $this->setTemplate('index');
 }
Exemplo n.º 21
0
 public function executeTextExport(sfWebRequest $request)
 {
     $this->setLayout(false);
     ParametersConfiguration::setUserPrefix(sfContext::getInstance()->getUser()->getAttribute('login'));
     $this->dbvalues = ParametersConfiguration::getAll();
     $this->Modules = $this->getContext()->get('Modules');
     $this->Kernel = $this->getContext()->get('Kernel');
     $this->missing_dep = $this->getContext()->get('DependenciesErrors');
     if ($request->isMethod(sfRequest::POST)) {
         $this->new = $this->getRequestParameter('module_name_to_add');
         $this->new_entry = $this->getRequestParameter('menu_entry');
         $this->delete = $this->getRequestParameter('module_name_to_delete');
         $this->delete_force = $this->getRequestParameter('module_name_to_delete_force');
     } else {
         $this->new = null;
         $this->new_entry = null;
         $this->delete = null;
         $this->delete_force = null;
     }
     $this->getResponse()->setContentType('text/plain');
 }