public function configure()
 {
     $pac_list = array();
     $choices = array();
     // Recherche les différents contrôleurs d'accès physiques
     for ($i = 1; $i <= ConfigurationHelper::getParameter(null, 'number_of_physical_access'); $i++) {
         $pac_list[] = ConfigurationHelper::getParameter(null, 'physical_access_controller' . $i);
     }
     $i = 1;
     // Recherche les noms données aux différents contrôleurs
     foreach ($pac_list as $pac) {
         $choices[] = ConfigurationHelper::getParameter($pac . $i, 'controller_name');
         $i++;
     }
     // Widgets
     if (count($choices) > 0) {
         $this->widgetSchema['physical_access_controller'] = new sfWidgetFormChoice(array('choices' => $choices, 'expanded' => false));
     }
     // Validators
     $this->validatorSchema['physical_access_controller'] = new sfValidatorChoice(array('choices' => array_keys($choices), 'required' => false));
     $this->validatorSchema['name'] = new sfXSSValidatorString(array('max_length' => 256));
     $this->validatorSchema['physical_access_id'] = new sfXSSValidatorString(array('max_length' => 256));
     // Labels
     $this->widgetSchema->setLabel('physical_access_id', 'Physical access identifier');
     if (count($choices) > 0) {
         $this->widgetSchema->setLabel('physical_access_controller', 'Configured Physical Access Controller');
     }
 }
 public function configure()
 {
     // Sort
     $activitySortCriteria = new Criteria();
     $activitySortCriteria->addAscendingOrderByColumn(ActivityPeer::NAME);
     $userSortCriteria = new Criteria();
     $userSortCriteria->addAscendingOrderByColumn(UserPeer::FAMILY_NAME);
     // Remove some fields
     //unset($this['usergroup_has_chief_list']);
     // Labels
     $activityItem = ConfigurationHelper::getParameter('Rename', 'activity_label');
     if (is_null($activityItem) || empty($activityItem)) {
         $activityItem = 'Activities';
     }
     $this->widgetSchema->setLabel('usergroup_has_chief_list', 'Leader(s)');
     $this->widgetSchema->setLabel('usergroup_has_user_list', 'Member(s)');
     $this->widgetSchema->setLabel('usergroup_has_activity_list', $activityItem);
     // Validators
     $this->validatorSchema['name'] = new sfXSSValidatorString(array('max_length' => 64));
     // Options
     $this->widgetSchema['usergroup_has_chief_list']->setOption('expanded', true);
     $this->widgetSchema['usergroup_has_chief_list']->setOption('criteria', $userSortCriteria);
     $this->validatorSchema['usergroup_has_chief_list']->setOption('required', true);
     $this->widgetSchema['usergroup_has_user_list']->setOption('expanded', true);
     $this->widgetSchema['usergroup_has_user_list']->setOption('criteria', $userSortCriteria);
     $this->widgetSchema['usergroup_has_activity_list']->setOption('expanded', true);
     $this->widgetSchema['usergroup_has_activity_list']->setOption('criteria', $activitySortCriteria);
     $this->validatorSchema['usergroup_has_activity_list']->setOption('required', true);
 }
 protected function execute($arguments = array(), $options = array())
 {
     $this->configuration = ProjectConfiguration::getApplicationConfiguration('frontend', 'prod', true);
     $this->context = sfContext::createInstance($this->configuration);
     $databaseManager = new sfDatabaseManager($this->configuration);
     $dbdsn = $databaseManager->getDatabase('propel')->getParameter('dsn');
     $dbusername = $databaseManager->getDatabase('propel')->getParameter('username');
     $dbpassword = $databaseManager->getDatabase('propel')->getParameter('password');
     $dbname = preg_replace('/^.*dbname=([^;=]+).*$/', '${1}', $dbdsn);
     ConfigurationHelper::load();
     $backup_method = ConfigurationHelper::getParameter('Backup', 'backup_method');
     $this->logSection('tempos', sprintf('Backup method: %s', $backup_method), 1024);
     if ($backup_method == 'ftp') {
         $backupname = 'tempos-backup.sql';
         $configname = ConfigurationHelper::getDefaultConfigurationFileName();
         $configpath = ConfigurationHelper::getDefaultConfigurationFilePath();
         copy($configpath, '/tmp/' . $configname);
         chdir('/tmp');
         system(sprintf('mysqldump --user=%s --password=%s %s > %s', escapeshellarg($dbusername), escapeshellarg($dbpassword), escapeshellarg($dbname), escapeshellarg($backupname)));
         $tmpfilename = 'tempos-backup-' . date('Y-m-d') . '.tar.gz';
         system(sprintf('tar zcf %s %s %s', escapeshellarg($tmpfilename), escapeshellarg($backupname), escapeshellarg($configname)));
         unlink($backupname);
         unlink($configname);
         try {
             FTPHelper::backupFile($tmpfilename);
         } catch (Exception $ex) {
             unlink($tmpfilename);
             throw $ex;
         }
         unlink($tmpfilename);
     }
 }
Beispiel #4
0
 protected function doSave($con = null)
 {
     $message = parent::doSave($con);
     $message = $this->getObject();
     /* // Ajout des infos concernant la réservation lors de l'envoi du message
     		$message->setText("TEST REUSSI\n\n\n--------------------\n\n\n".$message->getText()); */
     $recipient = $message->getRecipientUser();
     $to = $recipient->getEmailAddress();
     $sender = $message->getSenderUser();
     $from = null;
     if (ConfigurationHelper::getParameter('Email', 'use_mail', false)) {
         if (!empty($to)) {
             if (!is_null($sender)) {
                 $from = $sender->getEmailAddress();
                 if (empty($from)) {
                     $from = null;
                 }
             }
             MailHelper::send($to, $message->getSubject(), $message->getText(), $recipient->getFullName(), $from, $message->getSender());
         }
     }
     if (!is_null($sender)) {
         $messageSent = $message->copy();
         $messageSent->setOwnerId($sender->getId());
         $messageSent->setWasRead(true);
         $messageSent->save();
     }
     return $message;
 }
Beispiel #5
0
 public function configure()
 {
     unset($this['room_has_dayperiod_list']);
     unset($this['room_has_featurevalue_list']);
     // Sort
     $activitySortCriteria = new Criteria();
     $activitySortCriteria->addAscendingOrderByColumn(ActivityPeer::NAME);
     $energyactionSortCriteria = new Criteria();
     $energyactionSortCriteria->addAscendingOrderByColumn(EnergyactionPeer::NAME);
     // Layout
     $this->widgetSchema['address'] = new sfWidgetFormInputGeoComplete();
     $this->widgetSchema['description'] = new sfWidgetFormTextarea();
     $this->widgetSchema['room_has_activity_list']->setOption('expanded', true);
     $this->widgetSchema['room_has_activity_list']->setOption('criteria', $activitySortCriteria);
     $this->widgetSchema['room_has_energyaction_list']->setOption('criteria', $energyactionSortCriteria);
     $this->widgetSchema['zone_has_room_list'] = new sfWidgetFormZoneChoice(array('multiple' => true, 'add_empty' => false));
     $this->widgetSchema['room_has_energyaction_list']->setOption('expanded', true);
     // Validators
     $this->validatorSchema['capacity']->setOption('min', 1);
     $this->validatorSchema['zone_has_room_list']->setOption('required', true);
     $this->validatorSchema['name'] = new sfXSSValidatorString(array('max_length' => 64));
     // Labels
     $activityItem = ConfigurationHelper::getParameter('Rename', 'activity_label');
     if (is_null($activityItem) || empty($activityItem)) {
         $activityItem = 'Activities';
     }
     $this->widgetSchema->setLabel('room_has_activity_list', $activityItem);
     $this->widgetSchema->setLabel('zone_has_room_list', 'Zones');
     $this->widgetSchema->setLabel('room_has_energyaction_list', 'Energy actions');
     // Post-validators
     $this->validatorSchema->setPostValidator(new sfValidatorAnd(array(new sfValidatorPropelUnique(array('model' => 'Room', 'column' => array('name'))))));
 }
Beispiel #6
0
 public function executeMenu()
 {
     if ($this->getUser()->isAuthenticated()) {
         $this->modules = array();
         $this->modules['home'] = __('Home');
         if ($this->getUser()->hasCredential(array('admin', 'userManager'), false)) {
             $this->modules['user'] = __('Users');
             $this->modules['card'] = __('Cards');
         }
         if ($this->getUser()->hasCredential(array('admin', 'zoneManager'), false)) {
             $this->modules['zone'] = __('Zones');
         }
         if ($this->getUser()->hasCredential(array('admin', 'activityManager'), false)) {
             $activityModule = ConfigurationHelper::getParameter('Rename', 'activity_module');
             if (is_null($activityModule) || empty($activityModule)) {
                 $activityModule = 'Activities';
             }
             $this->modules['activity'] = __($activityModule);
         }
         if ($this->getUser()->hasCredential(array('admin', 'reportingManager'), false)) {
             $this->modules['reporting'] = __('Tools');
         }
         if ($this->getUser()->hasCredential(array('admin'), false)) {
             $this->modules['energyaction'] = __('Energy');
         }
     }
 }
 public function configure()
 {
     // Sort
     $activitySortCriteria = new Criteria();
     $activitySortCriteria->addAscendingOrderByColumn(ActivityPeer::NAME);
     // Choices
     $userTypeChoices = array(self::EVERYBODY => sfContext::getInstance()->getI18N()->__('Everybody'), self::LEADERS => sfContext::getInstance()->getI18N()->__('Leaders'), self::MEMBERS => sfContext::getInstance()->getI18N()->__('Members'), self::NONMEMBERS => sfContext::getInstance()->getI18N()->__('Non-members'));
     $createRuleChoices = array(self::ADD => sfContext::getInstance()->getI18N()->__('Add'), self::REPLACE => sfContext::getInstance()->getI18N()->__('Replace'), self::FILL => sfContext::getInstance()->getI18N()->__('Fill'), self::DELETE => sfContext::getInstance()->getI18N()->__('Delete'));
     // Layout
     $this->widgetSchema['User_type'] = new sfWidgetFormChoice(array('choices' => $userTypeChoices));
     $this->widgetSchema['Create_rule'] = new sfWidgetFormChoice(array('choices' => $createRuleChoices));
     $this->widgetSchema['Activity_id']->setOption('expanded', true);
     $this->widgetSchema['Activity_id']->setOption('multiple', true);
     $this->widgetSchema['Activity_id']->setOption('criteria', $activitySortCriteria);
     $this->widgetSchema['Zone_id'] = new sfWidgetFormZoneChoice(array('multiple' => true, 'add_empty' => false));
     $this->widgetSchema['unlimitedCredit'] = new sfWidgetFormInputCheckbox();
     $this->widgetSchema['UserGroup_id'] = new sfWidgetFormInputHidden();
     $this->widgetSchema['User_id'] = new sfWidgetFormInputHidden();
     $this->widgetSchema['Card_id'] = new sfWidgetFormInputHidden();
     $years = range(date('Y') - 128, date('Y') + 128);
     $this->widgetSchema['start']->setOption('years', array_combine($years, $years));
     $this->widgetSchema['stop']->setOption('years', array_combine($years, $years));
     // Labels
     $activityLabel = ConfigurationHelper::getParameter('Rename', 'activity_label');
     if (is_null($activityLabel) || empty($activityLabel)) {
         $activityLabel = 'Activity';
     }
     $this->widgetSchema->setLabel('User_type', 'Edit for');
     $this->widgetSchema->setLabel('Create_rule', 'Edition rule');
     $this->widgetSchema->setLabel('Activity_id', $activityLabel);
     $this->widgetSchema->setLabel('Zone_id', 'Zone');
     $this->widgetSchema->setLabel('UserGroup_id', 'Group');
     $this->widgetSchema->setLabel('unlimitedCredit', 'Unlimited access');
     $this->widgetSchema->setLabel('minimum_delay', 'Minimum number of hours in advance');
     $this->widgetSchema->setLabel('maximum_delay', 'Maximum number of days in advance');
     $this->widgetSchema->setLabel('minimum_duration', 'Minimum duration of reservations (minutes)');
     $this->widgetSchema->setLabel('maximum_duration', 'Maximum duration of reservations (minutes)');
     $this->widgetSchema->setLabel('hours_per_week', 'How many hours allowed per week (hours)');
     // Validators
     $step = sfConfig::get('app_booking_step');
     $this->validatorSchema['User_type'] = new sfValidatorChoice(array('choices' => array_keys($userTypeChoices), 'required' => true));
     $this->validatorSchema['Create_rule'] = new sfValidatorChoice(array('choices' => array_keys($createRuleChoices), 'required' => true));
     $this->validatorSchema['credit']->setOption('min', 1);
     $this->validatorSchema['Activity_id']->setOption('multiple', true);
     $this->validatorSchema['Zone_id']->setOption('multiple', true);
     $this->validatorSchema['unlimitedCredit'] = new sfValidatorBoolean(array('required' => false));
     $this->validatorSchema['minimum_delay']->setOption('min', 0);
     $this->validatorSchema['maximum_delay']->setOption('min', 0);
     $this->validatorSchema['minimum_duration']->setOption('min', $step);
     $this->validatorSchema['maximum_duration']->setOption('min', $step);
     $this->validatorSchema['hours_per_week']->setOption('min', 1);
     //$this->validatorSchema['hours_per_week']->setOption('max', 170);
     // Defaults
     $this->setDefault('Create_rule', self::REPLACE);
     $this->setDefault('start', strftime("%Y-%m-%d", time()));
     $this->setDefault('stop', strftime("%Y-%m-%d", strtotime('+1 year')));
     $this->setDefault('unlimitedCredit', true);
     // Post validators
     $this->validatorSchema->setPostValidator(new sfValidatorAnd(array(new sfValidatorSchemaCompare('stop', sfValidatorSchemaCompare::GREATER_THAN, 'start', array(), array('invalid' => 'The stop date must be after the start date.')), new sfValidatorSchemaCompare('maximum_duration', sfValidatorSchemaCompare::GREATER_THAN, 'minimum_duration', array(), array('invalid' => 'The maximum duration must be greater than the minimum duration.')))));
 }
 public function filter($values)
 {
     if (empty($values['ftp_password']) && ConfigurationHelper::hasParameter('Backup', 'ftp_password')) {
         $values['ftp_password'] = ConfigurationHelper::getParameter('Backup', 'ftp_password');
     }
     return $values;
 }
 public function configure()
 {
     $hac_list = array();
     $choices = array();
     $nb_hac = ConfigurationHelper::getParameter(null, 'number_of_home_automation');
     // Recherche les différents contrôleurs d'accès physiques
     if ($nb_hac > 0) {
         for ($i = 1; $i <= $nb_hac; $i++) {
             $hac_list[] = ConfigurationHelper::getParameter(null, 'home_automation_controller' . $i);
         }
     }
     $i = 1;
     // Recherche les noms données aux différents contrôleurs
     foreach ($hac_list as $hac) {
         $choices[] = ConfigurationHelper::getParameter($hac . $i, 'controller_name');
         $i++;
     }
     // Widgets
     if (count($choices) > 0) {
         $this->widgetSchema['home_automation_controller'] = new sfWidgetFormChoice(array('choices' => $choices, 'expanded' => false));
     }
     // Layout
     unset($this['status']);
     $this->widgetSchema['room_has_energyaction_list']->setOption('expanded', true);
     // Validators
     $this->validatorSchema['home_automation_controller'] = new sfValidatorChoice(array('choices' => array_keys($choices), 'required' => false));
     $this->validatorSchema['name'] = new sfXSSValidatorString(array('max_length' => 64));
     // Labels
     if (count($choices) > 0) {
         $this->widgetSchema->setLabel('home_automation_controller', 'Configured Home Automation Controller');
     }
     $this->widgetSchema->setLabel('delayUp', 'Up delay (minutes)');
     $this->widgetSchema->setLabel('delayDown', 'Down delay (minutes)');
     $this->widgetSchema->setLabel('identifier', 'Identifier');
     $this->widgetSchema->setLabel('processIdUp', 'Up PID');
     $this->widgetSchema->setLabel('processIdDown', 'Down PID');
     $this->widgetSchema->setLabel('start', 'Start');
     $this->widgetSchema->setLabel('stop', 'Stop');
     $this->widgetSchema->setLabel('room_has_energyaction_list', 'Rooms');
     // Options
     $minutes = array();
     for ($i = 0; $i < 60; $i += 5) {
         $minutes[$i] = str_pad($i, 2, '0', STR_PAD_LEFT);
     }
     $this->widgetSchema['start']->setOption('minutes', $minutes);
     $this->widgetSchema['stop']->setOption('minutes', $minutes);
     // Defaults
     $this->setDefault('start', '20:00');
     $this->setDefault('stop', '08:00');
     // Validators
     $this->validatorSchema['delayUp']->setOption('min', 0);
     $this->validatorSchema['delayDown']->setOption('min', 0);
     // Post-validators
     $this->validatorSchema->setPostValidator(new sfValidatorAnd(array(new sfValidatorPropelUnique(array('model' => 'Energyaction', 'column' => array('name'))))));
 }
 public function configure()
 {
     // Layout
     unset($this['ReservationReason_id']);
     unset($this['status']);
     unset($this['created_at']);
     unset($this['updated_at']);
     unset($this['is_activated']);
     $this->widgetSchema['comment'] = new sfWidgetFormTextarea();
     $this->widgetSchema['UserGroup_id'] = new sfWidgetFormInputHidden();
     $this->widgetSchema['User_id'] = new sfWidgetFormInputHidden();
     $this->widgetSchema['Card_id'] = new sfWidgetFormInputHidden();
     // Options
     $this->widgetSchema['date']->setOption('time', array('minutes' => array(0 => '00', 30 => '30')));
     // Labels
     $this->widgetSchema->setLabel('RoomProfile_id', 'Physical access');
     $activityItem = ConfigurationHelper::getParameter('Rename', 'activity_label');
     if (is_null($activityItem) || empty($activityItem)) {
         $activityItem = 'Activity';
     }
     $this->widgetSchema->setLabel('Activity_id', $activityItem);
     $this->widgetSchema->setLabel('Card_id', 'Card');
     $this->widgetSchema->setLabel('User_id', 'User');
     $this->widgetSchema->setLabel('duration', 'Duration (minutes)');
     $this->widgetSchema->setLabel('date', 'Date and time');
     $this->widgetSchema->setLabel('members_count', 'Members count');
     $this->widgetSchema->setLabel('guests_count', 'Guests count');
     $this->widgetSchema->setLabel('price', 'Price');
     $this->widgetSchema->setLabel('reservation_has_user_list', 'Other member(s)');
     // Checking specific fields name
     $custom1 = ConfigurationHelper::getParameter('Rename', 'reservation_custom_field_1');
     $custom2 = ConfigurationHelper::getParameter('Rename', 'reservation_custom_field_2');
     $custom3 = ConfigurationHelper::getParameter('Rename', 'reservation_custom_field_3');
     $this->widgetSchema->setLabel('custom_1', empty($custom1) ? 'hide' : $custom1);
     $this->widgetSchema->setLabel('custom_2', empty($custom2) ? 'hide' : $custom2);
     $this->widgetSchema->setLabel('custom_3', empty($custom3) ? 'hide' : $custom3);
     $userSortCriteria = new Criteria();
     $userSortCriteria->addAscendingOrderByColumn(UserPeer::FAMILY_NAME);
     $this->widgetSchema['reservation_has_user_list']->setOption('expanded', true);
     $this->widgetSchema['reservation_has_user_list']->setOption('criteria', $userSortCriteria);
     // Validators
     $step = sfConfig::get('app_booking_step');
     $this->validatorSchema['RoomProfile_id']->setOption('required', true);
     $this->validatorSchema['duration']->setOption('min', $step);
     $this->validatorSchema['members_count']->setOption('min', 0);
     $this->validatorSchema['guests_count']->setOption('min', 0);
     // Defaults
     $this->setDefault('members_count', 0);
     $this->setDefault('guests_count', 0);
     $this->validatorSchema->setPostValidator(new sfValidatorAnd(self::getReservationValidators()));
 }
 protected function execute($arguments = array(), $options = array())
 {
     $this->configuration = ProjectConfiguration::getApplicationConfiguration('frontend', 'prod', true);
     $this->context = sfContext::createInstance($this->configuration);
     ConfigurationHelper::load();
     if (ConfigurationHelper::getParameter('Network', '_need_update', false)) {
         $this->logSection('tempos', 'Update required.', 1024);
         if ($this->writeInterfaces()) {
             ConfigurationHelper::setParameter('Network', '_need_update', false);
             ConfigurationHelper::save();
         }
     } else {
         $this->logSection('tempos', 'No update required.', 1024);
     }
 }
Beispiel #12
0
 protected function processForm(sfWebRequest $request, sfForm $form)
 {
     $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
     if ($form->isValid()) {
         $nb = $form->getValue('physical_access_controller');
         // Récupère le contrôle d'accès physique sélectionné (grâce à sa position dans le ConfigurationHelper)
         $pac = ConfigurationHelper::getParameter(null, 'physical_access_controller' . ($nb + 1));
         $pac .= $nb + 1;
         $controller = ConfigurationHelper::getParameter($pac, 'controller_name');
         $name = RoomprofilePeer::buildName($controller, $form->getvalue('name'));
         $roomprofile = $form->save();
         $roomprofile->setName($name);
         $roomprofile->save();
         $this->redirect('roomprofile/index?roomId=' . $roomprofile->getRoomId());
     }
     $this->setTemplate('edit');
 }
 public function configure()
 {
     // Sort
     $activitySortCriteria = new Criteria();
     $activitySortCriteria->addAscendingOrderByColumn(ActivityPeer::NAME);
     // Layout
     $this->widgetSchema['Activity_id']->setOption('expanded', true);
     $this->widgetSchema['Activity_id']->setOption('criteria', $activitySortCriteria);
     $this->widgetSchema['Zone_id'] = new sfWidgetFormZoneChoice(array('multiple' => false, 'add_empty' => false));
     $this->widgetSchema['unlimitedCredit'] = new sfWidgetFormInputCheckbox();
     $this->widgetSchema['UserGroup_id'] = new sfWidgetFormInputHidden();
     $years = range(date('Y') - 128, date('Y') + 128);
     $this->widgetSchema['start']->setOption('years', array_combine($years, $years));
     $this->widgetSchema['stop']->setOption('years', array_combine($years, $years));
     // Labels
     $activityLabel = ConfigurationHelper::getParameter('Rename', 'activity_label');
     if (is_null($activityLabel) || empty($activityLabel)) {
         $activityLabel = 'Activity';
     }
     $this->widgetSchema->setLabel('Activity_id', $activityLabel);
     $this->widgetSchema->setLabel('Zone_id', 'Zone');
     $this->widgetSchema->setLabel('UserGroup_id', 'Group');
     $this->widgetSchema->setLabel('unlimitedCredit', 'Unlimited access');
     $this->widgetSchema->setLabel('minimum_delay', 'Minimum number of hours in advance');
     $this->widgetSchema->setLabel('maximum_delay', 'Maximum number of days in advance');
     $this->widgetSchema->setLabel('minimum_duration', 'Minimum duration of reservations (minutes)');
     $this->widgetSchema->setLabel('maximum_duration', 'Maximum duration of reservations (minutes)');
     $this->widgetSchema->setLabel('hours_per_week', 'How many hours allowed per week (hours)');
     $this->widgetSchema->setLabel('credit', 'Max. credits (hours)');
     // Validators
     $step = sfConfig::get('app_booking_step');
     $this->validatorSchema['credit']->setOption('min', 1);
     $this->validatorSchema['unlimitedCredit'] = new sfValidatorBoolean(array('required' => false));
     $this->validatorSchema['minimum_delay']->setOption('min', 0);
     $this->validatorSchema['maximum_delay']->setOption('min', 0);
     $this->validatorSchema['minimum_duration']->setOption('min', $step);
     $this->validatorSchema['maximum_duration']->setOption('min', $step);
     $this->validatorSchema['hours_per_week']->setOption('min', 1);
     //$this->validatorSchema['hours_per_week']->setOption('max', 170);
     // Defaults
     $this->setDefault('start', strftime("%Y-%m-%d", time()));
     $this->setDefault('stop', strftime("%Y-%m-%d", strtotime('+1 year')));
     $this->setDefault('unlimitedCredit', true);
     // Post validators
     $this->validatorSchema->setPostValidator(new sfValidatorAnd(array(new sfValidatorSchemaCompare('stop', sfValidatorSchemaCompare::GREATER_THAN, 'start', array(), array('invalid' => 'The stop date must be after the start date.')), new sfValidatorSchemaCompare('maximum_duration', sfValidatorSchemaCompare::GREATER_THAN, 'minimum_duration', array(), array('invalid' => 'The maximum duration must be greater than the minimum duration.')))));
 }
Beispiel #14
0
 public static function backupFile($file)
 {
     $host = ConfigurationHelper::getParameter('Backup', 'ftp_host');
     $service = ConfigurationHelper::getParameter('Backup', 'ftp_service', 21);
     $username = ConfigurationHelper::getParameter('Backup', 'ftp_username');
     $password = ConfigurationHelper::getParameter('Backup', 'ftp_password');
     $result = false;
     $ch = ftp_connect($host, $service);
     if ($ch) {
         $lr = ftp_login($ch, $username, $password);
         if ($lr) {
             $result = ftp_put($ch, basename($file), $file, FTP_BINARY);
         }
         ftp_close($ch);
     }
     if (!$result) {
         throw new Exception('FTP backup file failed.');
     }
 }
Beispiel #15
0
 public function configure()
 {
     // Sort
     $sortCriteria = new Criteria();
     $sortCriteria->addAscendingOrderByColumn(ActivityPeer::NAME);
     // Layout
     $this->widgetSchema['activity_has_feature_list']->setOption('expanded', true);
     $this->widgetSchema['activity_has_feature_list']->setOption('criteria', $sortCriteria);
     // Validators
     $this->validatorSchema['name'] = new sfXSSValidatorString(array('max_length' => 128));
     // Labels
     $activityItem = ConfigurationHelper::getParameter('Rename', 'activity_label');
     if (is_null($activityItem) || empty($activityItem)) {
         $activityItem = 'Activities';
     }
     $this->widgetSchema->setLabel('activity_has_feature_list', $activityItem);
     // Post-validators
     $this->validatorSchema->setPostValidator(new sfValidatorAnd(array(new sfValidatorPropelUnique(array('model' => 'Feature', 'column' => array('name'))))));
 }
Beispiel #16
0
 public function configure()
 {
     $this->setWidgets(array('zone' => new sfWidgetFormZoneChoice(array('current_zone' => null)), 'activities' => new sfWidgetFormPropelChoiceMany(array('model' => 'Activity', 'add_empty' => false, 'expanded' => true)), 'begin_date' => new sfWidgetFormI18nDate(array('culture' => 'fr', 'month_format' => 'number')), 'end_date' => new sfWidgetFormI18nDate(array('culture' => 'fr', 'month_format' => 'number'))));
     $years = range(date('Y') - 128, date('Y'));
     $this->widgetSchema['begin_date']->setOption('years', array_combine($years, $years));
     $this->widgetSchema['end_date']->setOption('years', array_combine($years, $years));
     $this->setDefault('begin_date', date('Y/m/d', strtotime('- 1 month')));
     $this->setDefault('end_date', date('Y/m/d'));
     $this->setValidators(array('zone' => new sfValidatorZoneChoice(array('current_zone' => null, 'required' => false)), 'activities' => new sfValidatorPropelChoiceMany(array('model' => 'Activity', 'column' => 'id', 'required' => false)), 'begin_date' => new sfValidatorDate(array('required' => true)), 'end_date' => new sfValidatorDate(array('required' => true))));
     $activityItem = ConfigurationHelper::getParameter('Rename', 'activity_label');
     if (is_null($activityItem) || empty($activityItem)) {
         $activityItem = 'Activities';
     }
     $this->widgetSchema->setLabels(array('zone' => 'Zone', 'activities' => $activityItem, 'begin_date' => 'Start date', 'end_date' => 'Stop date'));
     $this->widgetSchema->setNameFormat('occupancy[%s]');
     $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);
     // Post validators
     $this->validatorSchema->setPostValidator(new sfValidatorSchemaCompare('end_date', sfValidatorSchemaCompare::GREATER_THAN_EQUAL, 'begin_date', array(), array('invalid' => 'The stop date must be after the start date.')));
 }
Beispiel #17
0
 public static function send($to, $subject, $body, $to_name = null, $from = null, $from_name = null)
 {
     $encryption_method = ConfigurationHelper::getParameter('Email', 'smtp_encryption_method', false);
     $host = ConfigurationHelper::getParameter('Email', 'smtp_host');
     $service = ConfigurationHelper::getParameter('Email', 'smtp_service');
     $use_authentication = ConfigurationHelper::getParameter('Email', 'smtp_use_authentication');
     $username = ConfigurationHelper::getParameter('Email', 'smtp_username');
     $password = ConfigurationHelper::getParameter('Email', 'smtp_password');
     $signature = ConfigurationHelper::getParameter('Email', 'signature');
     if (is_null($from) || ConfigurationHelper::getParameter('Email', 'override_from')) {
         $from = ConfigurationHelper::getParameter('Email', 'from');
     }
     switch ($encryption_method) {
         case 'ssl':
             $encryption = Swift_Connection_SMTP::ENC_SSL;
             break;
         case 'tls':
             $encryption = Swift_Connection_SMTP::ENC_TLS;
             break;
         case 'none':
         default:
             $encryption = Swift_Connection_SMTP::ENC_OFF;
             break;
     }
     $smtp = new Swift_Connection_SMTP($host, $service, $encryption);
     if ($use_authentication) {
         $smtp->setUsername($username);
         $smtp->setPassword($password);
     }
     $message = new Swift_Message($subject, sprintf("%s\n\n%s", $body, $signature));
     $swift = new Swift($smtp);
     if (!is_null($to_name)) {
         $to = new Swift_Address($to, $to_name);
     } else {
         $to = new Swift_Address($to);
     }
     if (!is_null($from_name)) {
         $from = new Swift_Address($from, $from_name);
     } else {
         $from = new Swift_Address($from);
     }
     $swift->send($message, $to, $from);
 }
Beispiel #18
0
 protected function processForm(sfWebRequest $request, sfForm $form)
 {
     $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
     if ($form->isValid()) {
         if (!is_null($form->getValue('home_automation_controller'))) {
             $nb = $form->getValue('home_automation_controller');
             // Récupère le contrôleur domotique sélectionné (grâce à sa position dans le ConfigurationHelper)
             $hac = ConfigurationHelper::getParameter(null, 'home_automation_controller' . ($nb + 1));
             $hac .= $nb + 1;
             $controller = ConfigurationHelper::getParameter($hac, 'controller_name');
             $name = EnergyactionPeer::buildName($controller, $form->getvalue('name'));
             $energyaction = $form->save();
             $energyaction->setName($name);
             $energyaction->save();
         } else {
             $energyaction = $form->save();
         }
         $this->redirect('energyaction/index');
     }
 }
Beispiel #19
0
 public function executePrepareLogin(sfWebRequest $request)
 {
     $this->forward404Unless($request->isMethod('post'));
     if (!$this->getUser()->isAuthenticated()) {
         $username = $request->getParameter('username');
         $password = $request->getParameter('password');
         $user = null;
         if (ConfigurationHelper::getParameter('General', 'auth_ldap_choice', false)) {
             // Need to authenticate with LDAP server
             $server = ConfigurationHelper::getParameter('General', 'auth_ldap_host', '');
             $domain = ConfigurationHelper::getParameter('General', 'auth_ldap_domain', '');
             $ldap = @ldap_connect($server);
             // ex: myldapserver.company.com
             if ($ldap) {
                 ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
                 ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);
                 // Process the username for good domain name
                 $ldpa_username = $username . '@' . $domain;
                 // ex: Administrator@MYDOMAIN.com
                 $bind = @ldap_bind($ldap, $ldpa_username, $password);
                 if ($bind) {
                     $user = UserPeer::retrieveByLogin($username);
                 }
                 ldap_close($ldap);
             }
         } else {
             $user = UserPeer::authenticate($username, $password);
         }
         if (!empty($user) && $user->getIsActive()) {
             $this->getUser()->setTemposUser($user);
             $referer = $request->getParameter('referer');
             if (empty($referer)) {
                 $referer = 'home/index';
             }
             $this->redirect($referer);
         } else {
             $this->getUser()->setFlash('loginError', true);
         }
     }
     $this->redirect('login/login');
 }
Beispiel #20
0
 public function configure()
 {
     $i18n = sfContext::getInstance()->getI18N();
     $active_choices = array(null => $i18n->__('Any'), true => $i18n->__('Yes'), false => $i18n->__('No'));
     $activity_name = ConfigurationHelper::getParameter('Rename', 'activity_label');
     $free_field_1_name = ConfigurationHelper::getParameter('Rename', 'reservation_custom_field_1');
     $free_field_2_name = ConfigurationHelper::getParameter('Rename', 'reservation_custom_field_2');
     $free_field_3_name = ConfigurationHelper::getParameter('Rename', 'reservation_custom_field_3');
     if (empty($activity_name)) {
         $activity_name = $i18n->__('Activity');
     }
     $fields_choices = array($i18n->__('Date'), $i18n->__('User'), $activity_name, $i18n->__('Duration'), $i18n->__('Room'), $i18n->__('Reason'), $i18n->__('Comment'), $i18n->__('Group'), $i18n->__('Members count'), $i18n->__('Guests count'), $i18n->__('Status'), $i18n->__('Price'), $i18n->__('Features'));
     if (!empty($free_field_1_name)) {
         $fields_choices[90] = $free_field_1_name;
         // 91
     }
     if (!empty($free_field_2_name)) {
         $fields_choices[91] = $free_field_2_name;
         // 92
     }
     if (!empty($free_field_3_name)) {
         $fields_choices[92] = $free_field_3_name;
         // 93
     }
     $this->setWidgets(array('users' => new sfWidgetFormPropelChoiceMany(array('model' => 'User', 'add_empty' => false, 'expanded' => true)), 'usergroups' => new sfWidgetFormPropelChoiceMany(array('model' => 'Usergroup', 'add_empty' => false, 'expanded' => true)), 'activities' => new sfWidgetFormPropelChoiceMany(array('model' => 'Activity', 'add_empty' => false, 'expanded' => true)), 'zones' => new sfWidgetFormPropelChoiceMany(array('model' => 'Zone', 'add_empty' => false, 'expanded' => true)), 'rooms' => new sfWidgetFormPropelChoiceMany(array('model' => 'Room', 'add_empty' => false, 'expanded' => true)), 'begin_date' => new sfWidgetFormI18nDate(array('culture' => 'fr', 'month_format' => 'number')), 'end_date' => new sfWidgetFormI18nDate(array('culture' => 'fr', 'month_format' => 'number')), 'fields' => new sfWidgetFormChoiceMany(array('choices' => $fields_choices, 'expanded' => true))));
     $begin_years = range(date('Y') - 128, date('Y') + 20);
     $end_years = range(date('Y') - 128, date('Y') + 20);
     $this->widgetSchema['begin_date']->setOption('years', array_combine($begin_years, $begin_years));
     $this->widgetSchema['end_date']->setOption('years', array_combine($end_years, $end_years));
     $this->setDefault('begin_date', date('Y/m/d', strtotime('- 1 month')));
     $this->setDefault('end_date', date('Y/m/d'));
     // Select default selected filters
     $this->setDefault('fields', array(0, 1, 2, 3, 4, 7));
     // array_keys($fields_choices));
     $this->setValidators(array('users' => new sfValidatorPropelChoiceMany(array('model' => 'User', 'column' => 'id', 'required' => false)), 'usergroups' => new sfValidatorPropelChoiceMany(array('model' => 'Usergroup', 'column' => 'id', 'required' => false)), 'activities' => new sfValidatorPropelChoiceMany(array('model' => 'Activity', 'column' => 'id', 'required' => false)), 'zones' => new sfValidatorPropelChoiceMany(array('model' => 'Zone', 'column' => 'id', 'required' => false)), 'rooms' => new sfValidatorPropelChoiceMany(array('model' => 'Room', 'column' => 'id', 'required' => false)), 'begin_date' => new sfValidatorDate(array('required' => true)), 'end_date' => new sfValidatorDate(array('required' => true)), 'fields' => new sfValidatorChoiceMany(array('choices' => array_keys($fields_choices), 'required' => true))));
     $this->widgetSchema->setLabels(array('users' => 'Users', 'usergroups' => 'Groups', 'activities' => $activity_name, 'zones' => 'Zones', 'rooms' => 'Rooms', 'begin_date' => 'Start date', 'end_date' => 'Stop date', 'fields' => 'Fields'));
     $this->widgetSchema->setNameFormat('reporting[%s]');
     $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);
     // Post validators
     $this->validatorSchema->setPostValidator(new sfValidatorSchemaCompare('end_date', sfValidatorSchemaCompare::GREATER_THAN_EQUAL, 'begin_date', array(), array('invalid' => 'The stop date must be after the start date.')));
 }
 public function configure()
 {
     $c = new Criteria();
     // Choices
     $active_choices = array(null => sfContext::getInstance()->getI18N()->__('Any'), true => sfContext::getInstance()->getI18N()->__('Yes'), false => sfContext::getInstance()->getI18N()->__('No'));
     $this->setWidgets(array('login' => new sfWidgetFormInput(), 'family_name' => new sfWidgetFormInput(), 'surname' => new sfWidgetFormInput(), 'usergroupsAsLeader' => new sfWidgetFormPropelChoiceMany(array('model' => 'Usergroup', 'add_empty' => false, 'expanded' => true, 'criteria' => $c)), 'usergroupsAsMember' => new sfWidgetFormPropelChoiceMany(array('model' => 'Usergroup', 'add_empty' => false, 'expanded' => true, 'criteria' => $c)), 'activities' => new sfWidgetFormPropelChoiceMany(array('model' => 'Activity', 'add_empty' => false, 'expanded' => true)), 'is_active' => new sfWidgetFormChoice(array('choices' => $active_choices)), 'card_number' => new sfWidgetFormInput(), 'begin_date' => new sfWidgetFormI18nDate(array('culture' => 'fr', 'month_format' => 'number')), 'end_date' => new sfWidgetFormI18nDate(array('culture' => 'fr', 'month_format' => 'number')), 'email_address' => new sfWidgetFormInput(), 'address' => new sfWidgetFormInput(), 'phone_number' => new sfWidgetFormInput()));
     $years = range(date('Y') - 128, date('Y'));
     $this->widgetSchema['begin_date']->setOption('years', array_combine($years, $years));
     $this->widgetSchema['end_date']->setOption('years', array_combine($years, $years));
     $minimum_birth_date = '01/01/1910';
     $this->setDefault('is_active', null);
     $this->setDefault('begin_date', $minimum_birth_date);
     $this->setDefault('end_date', date('m/d/Y'));
     $this->setValidators(array('login' => new sfValidatorString(array('max_length' => 64, 'required' => false)), 'family_name' => new sfValidatorString(array('max_length' => 64, 'required' => false)), 'surname' => new sfValidatorString(array('max_length' => 64, 'required' => false)), 'usergroupsAsLeader' => new sfValidatorPropelChoiceMany(array('model' => 'Usergroup', 'column' => 'id', 'required' => false)), 'usergroupsAsMember' => new sfValidatorPropelChoiceMany(array('model' => 'Usergroup', 'column' => 'id', 'required' => false)), 'activities' => new sfValidatorPropelChoiceMany(array('model' => 'Activity', 'column' => 'id', 'required' => false)), 'is_active' => new sfValidatorChoice(array('choices' => array_keys($active_choices), 'required' => false)), 'card_number' => new sfValidatorString(array('max_length' => 32, 'required' => false)), 'begin_date' => new sfValidatorDate(array('required' => false)), 'end_date' => new sfValidatorDate(array('required' => false)), 'email_address' => new sfValidatorString(array('max_length' => 128, 'required' => false)), 'address' => new sfValidatorString(array('max_length' => 256, 'required' => false)), 'phone_number' => new sfValidatorString(array('max_length' => 64, 'required' => false))));
     $activityItem = ConfigurationHelper::getParameter('Rename', 'activity_label');
     if (is_null($activityItem) || empty($activityItem)) {
         $activityItem = 'Activities';
     }
     $this->widgetSchema->setLabels(array('login' => 'Username', 'family_name' => 'Family name', 'surname' => 'Surname', 'usergroupsAsLeader' => 'Groups as leader', 'usergroupsAsMember' => 'Groups as member', 'activities' => $activityItem, 'is_active' => 'Is active', 'card_number' => 'Card number', 'begin_date' => 'Minimum birth date', 'end_date' => 'Maximum birth date', 'email_address' => 'Email address', 'address' => 'Address', 'phone_number' => 'Phone number'));
     $this->widgetSchema->setNameFormat('userSearch[%s]');
     $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);
     // Post validators
     $this->validatorSchema->setPostValidator(new sfValidatorSchemaCompare('end_date', sfValidatorSchemaCompare::GREATER_THAN_EQUAL, 'begin_date', array(), array('invalid' => 'The stop date must be after the start date.')));
 }
Beispiel #22
0
?>
</p>

<?php 
if (count($usergroup_list) > 0) {
    ?>

<table class="list">
  <thead>
    <tr>
			<th><?php 
    echo sort_link('usergroup', 'index', 'name', __('Name'), $sort_direction, $sort_column);
    ?>
</th>
      <th><?php 
    $activityItem = ConfigurationHelper::getParameter('Rename', 'activity_label');
    if (is_null($activityItem) || empty($activityItem)) {
        $activityItem = 'Activities';
    }
    echo __($activityItem);
    ?>
</th>
      <th><?php 
    echo __('Leader(s)');
    ?>
</th>
      <th><?php 
    echo __('Members count');
    ?>
</th>
      <th><?php 
 /**
  * Get the configuration value.
  *
  * \param $key The key of the configuration value to get value from.
  * \param $default The default value.
  * \return The value if a configuration with the specified name exists, or $default otherwise.
  */
 public function getParameter($key, $default = null, $controller_id = null)
 {
     $name = $this->getName();
     if (is_null($default)) {
         if (isset($this->defaultValues[$key])) {
             $default = $this->defaultValues[$key];
         }
     }
     if (!is_null($controller_id)) {
         $name .= $controller_id;
     }
     return ConfigurationHelper::getParameter($name, $key, $default);
 }
Beispiel #24
0
    }
}
?>
		</tr>
	</thead>
	<tbody>
		<?php 
$startIndex = $room->getOverallStartIndex();
$stopIndex = $room->getOverallStopIndex();
$minimum_date = $activity->getMinimumDate();
$printTitle = ConfigurationHelper::getParameter('Print', 'print_title');
$printOptions = array('reserved_by' => ConfigurationHelper::getParameter('Print', 'print_reserved_by'), 'reserved_for' => ConfigurationHelper::getParameter('Print', 'print_reserved_for'), 'reason' => ConfigurationHelper::getParameter('Print', 'print_reason'), 'time' => ConfigurationHelper::getParameter('Print', 'print_time'), 'duration' => ConfigurationHelper::getParameter('Print', 'print_duration'), 'custom1' => ConfigurationHelper::getParameter('Print', 'print_custom_field1'), 'custom2' => ConfigurationHelper::getParameter('Print', 'print_custom_field2'), 'custom3' => ConfigurationHelper::getParameter('Print', 'print_custom_field3'), 'status' => ConfigurationHelper::getParameter('Print', 'print_status'), 'profile' => ConfigurationHelper::getParameter('Print', 'print_profile'));
$tabRes = array(array());
$free_field_1_name = ConfigurationHelper::getParameter('Rename', 'reservation_custom_field_1');
$free_field_2_name = ConfigurationHelper::getParameter('Rename', 'reservation_custom_field_2');
$free_field_3_name = ConfigurationHelper::getParameter('Rename', 'reservation_custom_field_3');
// First column
for ($i = $startIndex; $i < $stopIndex; ++$i) {
    $tst = mktime($i / 2, $i % 2 * 30);
    if ($i % 2 == 0) {
        if ($i != $stopIndex - 1) {
            $tabRes[0][$i] = '<th rowspan="1" class="hour">' . strftime('%H:%M', $tst) . '</th><td class="hide"></td>';
        } else {
            $tabRes[0][$i] = '<th rowspan="1" class="half">' . strftime('%H:%M', $tst) . '</th><td class="hide"></td>';
        }
    } else {
        if ($i == $startIndex) {
            $tabRes[0][$i] = '<th rowspan="1" class="half">' . strftime('%H:%M', $tst) . '</th><td class="hide"></td>';
        } else {
            $tabRes[0][$i] = '<th rowspan="1"></th><td class="hide"></td>';
        }
Beispiel #25
0
	<?php 
echo $authenticated ? __('logout') : __('login');
?>
</a>
<?php 
if (!$authenticated) {
    ?>
	- <a href="<?php 
    echo url_for('login/cardLogin');
    ?>
"><?php 
    echo __('login with a card');
    ?>
</a>
	<?php 
    if (ConfigurationHelper::getParameter('General', 'allow_registration', true)) {
        ?>
		- <a href="<?php 
        echo url_for('login/register');
        ?>
"><?php 
        echo __('register');
        ?>
</a>
	<?php 
    }
} else {
    ?>
	<?php 
    if ($is_admin) {
        ?>
Beispiel #26
0
 public function executeIndex(sfWebRequest $request)
 {
     $i18n = sfContext::getInstance()->getI18N();
     // Disable CSRF protection
     $this->form = new ReportingForm(array(), array(), false);
     $formName = $this->form->getName();
     $this->step = sfConfig::get('app_max_reservations_on_reporting');
     $this->getUser()->syncParameters($this, 'reporting', 'index', array('offset', 'limit', $formName, 'sort_column', 'sort_direction'), $request);
     if (is_null($this->sort_column)) {
         $this->sort_column = 'date';
         $this->sort_direction = 'up';
     }
     if (is_null($this->offset)) {
         $this->offset = 0;
     }
     if (is_null($this->limit) || $this->limit <= 0) {
         $this->limit = $this->step;
     }
     $c = new Criteria();
     SortCriteria::addSortCriteria($c, $this->sort_column, ReservationPeer::getSortAliases(), $this->sort_direction);
     $this->filtered = false;
     if (!is_null($this->{$formName})) {
         $this->filtered = true;
         $this->form->bind($this->{$formName}, $request->getFiles($formName));
         if ($this->form->isValid()) {
             $this->reservation_list = ReservationPeer::report($this->form->getValue('users'), $this->form->getValue('usergroups'), $this->form->getValue('activities'), $this->form->getValue('zones'), $this->form->getValue('rooms'), strtotime($this->form->getValue('begin_date')), strtotime($this->form->getValue('end_date')), $c);
             $this->count = count($this->reservation_list);
             $this->entire_reservation_list = $this->reservation_list;
             $this->reservation_list = array_slice($this->reservation_list, $this->offset, $this->limit);
         } else {
             $this->count = 0;
             $this->reservation_list = array();
         }
     } else {
         $this->count = 0;
         $this->reservation_list = array();
     }
     if ($this->offset < 0 || $this->offset >= $this->count && $this->count > 0) {
         $this->forward404('Invalid offset/count values.');
     }
     if (!is_null($export = $request->getParameter('export'))) {
         $this->forward404Unless(in_array($export, array('csv', 'pdf')), sprintf('Unhandled value "%s" for export', $export));
         sfConfig::set('sf_web_debug', false);
         $activity_name = ConfigurationHelper::getParameter('Rename', 'activity_label');
         if (empty($activity_name)) {
             $activity_name = $i18n->__('Activity');
         }
         $free_field_1_name = ConfigurationHelper::getParameter('Rename', 'reservation_custom_field_1');
         $free_field_2_name = ConfigurationHelper::getParameter('Rename', 'reservation_custom_field_2');
         $free_field_3_name = ConfigurationHelper::getParameter('Rename', 'reservation_custom_field_3');
         $this->all_rows = array();
         $fields = $this->form->getValue('fields');
         foreach ($this->entire_reservation_list as $reservation) {
             //If there's is a temporary group, we modify the name to display "Perso. (first user, ...)"
             $resa_group_name = null;
             $ug = $reservation->getUsergroup();
             if (!is_null($ug)) {
                 $resa_group_name = $ug->getName();
             }
             $this->all_rows[] = array();
             end($this->all_rows);
             // Check which field we need to display.
             foreach ($fields as $field_id) {
                 // See lib\form\ReportingForm.class.php for indexes
                 switch ($field_id) {
                     case 0:
                         $this->all_rows[key($this->all_rows)][] = array($i18n->__('Date'), $reservation->getDate());
                         break;
                     case 1:
                         $this->all_rows[key($this->all_rows)][] = array($i18n->__('User'), $reservation->getUser()->getFullName());
                         break;
                     case 2:
                         $this->all_rows[key($this->all_rows)][] = array($activity_name, $reservation->getActivity()->getName());
                         break;
                     case 3:
                         $this->all_rows[key($this->all_rows)][] = array($i18n->__('Duration'), number_format($reservation->getDuration()));
                         break;
                     case 4:
                         $this->all_rows[key($this->all_rows)][] = array($i18n->__('Room'), $reservation->getRoomprofile()->getRoom()->getName());
                         break;
                     case 5:
                         $this->all_rows[key($this->all_rows)][] = array($i18n->__('Reason'), !is_null($reservation->getReservationreason()) ? $reservation->getReservationreason()->getName() : null);
                         break;
                     case 6:
                         $this->all_rows[key($this->all_rows)][] = array($i18n->__('Comment'), $reservation->getComment());
                         break;
                     case 7:
                         $this->all_rows[key($this->all_rows)][] = array($i18n->__('Group'), $resa_group_name);
                         break;
                     case 8:
                         $this->all_rows[key($this->all_rows)][] = array($i18n->__('Members count'), number_format($reservation->getMembersCount()));
                         break;
                     case 9:
                         $this->all_rows[key($this->all_rows)][] = array($i18n->__('Guests count'), number_format($reservation->getGuestsCount()));
                         break;
                     case 10:
                         $this->all_rows[key($this->all_rows)][] = array($i18n->__('Status'), number_format($reservation->getStatus()));
                         break;
                     case 11:
                         $this->all_rows[key($this->all_rows)][] = array($i18n->__('Price'), number_format($reservation->getPrice()));
                         break;
                     case 12:
                         $valuedFeaturesArray = $reservation->getRoomprofile()->getRoom()->getValuedFeaturesArray();
                         $concat = '';
                         foreach ($valuedFeaturesArray as $featureName => $values) {
                             $concat .= $featureName . '=' . $values . ' | ';
                         }
                         $concat = rtrim($concat, ' | ');
                         $this->all_rows[key($this->all_rows)][] = array($i18n->__('Features'), $concat);
                         break;
                     case 90:
                         $this->all_rows[key($this->all_rows)][] = array($free_field_1_name, $reservation->getCustom1());
                         break;
                     case 91:
                         $this->all_rows[key($this->all_rows)][] = array($free_field_2_name, $reservation->getCustom2());
                         break;
                     case 92:
                         $this->all_rows[key($this->all_rows)][] = array($free_field_3_name, $reservation->getCustom3());
                         break;
                 }
             }
         }
         if ($export == 'csv') {
             $this->setLayout(false);
             $this->getResponse()->clearHttpHeaders();
             $this->getResponse()->setHttpHeader('Pragma: public', true);
             $this->getResponse()->setHttpHeader('Content-disposition', sprintf('attachment; filename="%s"', 'reporting-' . date('Y-m-d') . '.csv'));
             $this->getResponse()->setContentType('text/csv; charset=utf-8');
             $this->getResponse()->sendHttpHeaders();
             $this->setTemplate('exportCSV');
         } else {
             if ($export == 'pdf') {
                 $config = sfTCPDFPluginConfigHandler::loadConfig();
                 $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
                 // set document information
                 $pdf->SetCreator(PDF_CREATOR);
                 $pdf->SetAuthor('ISLOG Tempos');
                 $pdf->SetTitle('Tempos report export');
                 $pdf->SetSubject('Tempos export');
                 $pdf->SetKeywords('Tempos, report, ISLOG');
                 $pdf->SetHeaderData(sfConfig::get('app_has_logo'), PDF_HEADER_LOGO_WIDTH, $i18n->__('Report'), sprintf($i18n->__('Usage report from %s to %s'), $this->form->getValue('begin_date'), $this->form->getValue('end_date')));
                 $pdf->setFooterData(array(0, 64, 0), array(0, 64, 128));
                 $pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
                 $pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
                 $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
                 $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
                 $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
                 $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
                 $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
                 $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
                 $pdf->setFontSubsetting(true);
                 $pdf->SetFont('dejavusans', '', 10, '', true);
                 $pdf->AddPage();
                 $this->writeHtmlTable($pdf, $this->all_rows);
                 $pdf->Output('reporting-' . date('Y-m-d') . '.pdf', 'I');
                 exit;
             }
         }
     }
 }
 private static function findHac($action)
 {
     $action_controllername = $action->getConfiguredControllerName();
     $hac_infos = BaseHomeAutomationController::findHacFromNameIdentifier($action_controllername);
     // var_dump($action_controllername);
     if (is_null($hac_infos)) {
         return null;
     }
     $hac_name = $hac_infos['name'];
     // print 'hac_name: ';
     // var_dump($hac_name);
     $hac_id = $hac_infos['id'];
     // print 'hac_id: ';
     // var_dump($hac_id);
     $hac_selec = ConfigurationHelper::getParameter(null, $hac_name);
     // print 'hac_selec: ';
     // var_dump($hac_selec);
     $hac_conf = ConfigurationHelper::getNamespace($hac_selec . $hac_id);
     // print 'hac_conf: ';
     // var_dump($hac_conf);
     // var_dump($hac_infos);
     $hac = BaseHomeAutomationController::create($hac_selec, $hac_conf);
     // var_dump($hac);
     return $hac;
 }
Beispiel #28
0
 public function executeUpdate(sfWebRequest $request)
 {
     $this->forward404Unless($request->isMethod('post'));
     $post_parameters = $request->getParameter('configuration');
     $this->nb_controller = intval($post_parameters['number_of_physical_access']);
     $this->nb_home_automation = intval($post_parameters['number_of_home_automation']);
     $this->physical_access_controllers = BasePhysicalAccessController::getControllers();
     $this->home_automation_controllers = BaseHomeAutomationController::getControllers();
     $this->form = new ConfigurationForm(null, array('nb_pac' => $this->nb_controller, 'nb_hac' => $this->nb_home_automation));
     if ($this->nb_controller > $this->form->getMaxControllers()) {
         $this->nb_controller = $this->form->getMaxControllers();
     }
     if ($this->nb_home_automation > $this->form->getMaxHomeAutomation()) {
         $this->nb_home_automation = $this->form->getMaxHomeAutomation();
     }
     // Gestion des contrôleurs d'accès supplémentaires et de leurs valeurs par défaut (si l'on augmente le nombre de contrôleurs d'accès)
     for ($i = 1; $i <= $this->nb_controller; $i++) {
         if (!isset($post_parameters['physical_access_controller' . $i])) {
             foreach ($this->physical_access_controllers as $pac => $name) {
                 $controller = BasePhysicalAccessController::create($pac);
                 $post_parameters[$pac . $i] = $controller->getDefaultValues();
                 // On modifie le nom identifiant par défaut et on y ajoute i
                 $post_parameters[$pac . $i]['controller_name'] = $controller->getName() . $i;
             }
         }
     }
     // Gestion des contrôleurs domotiques supplémentaires et de leurs valeurs par défaut (si l'on augmente le nombre de contrôleurs domotiques)
     for ($i = 1; $i <= $this->nb_home_automation; $i++) {
         if (!isset($post_parameters['home_automation_controller' . $i])) {
             foreach ($this->home_automation_controllers as $hac => $name) {
                 $controller = BaseHomeAutomationController::create($hac);
                 $post_parameters[$hac . $i] = $controller->getDefaultValues();
                 // On modifie le nom identifiant par défaut et on y ajoute i
                 $post_parameters[$hac . $i]['controller_name'] = $controller->getName() . $i;
             }
         }
     }
     // Gestion des contrôleurs d'accès en trop (si l'on réduit le nombre de contrôleurs d'accès)
     for ($i = $this->nb_controller + 1; $i <= $this->form->getMaxControllers(); $i++) {
         if (isset($post_parameters['physical_access_controller' . $i])) {
             unset($post_parameters['physical_access_controller' . $i]);
             foreach ($this->physical_access_controllers as $pac => $name) {
                 unset($post_parameters[$pac . $i]);
             }
         }
     }
     // Gestion des contrôleurs domotiques en trop (si l'on réduit le nombre de contrôleurs domotiques)
     for ($i = $this->nb_home_automation + 1; $i <= $this->form->getMaxHomeAutomation(); $i++) {
         if (isset($post_parameters['home_automation_controller' . $i])) {
             unset($post_parameters['home_automation_controller' . $i]);
             foreach ($this->home_automation_controllers as $hac => $name) {
                 unset($post_parameters[$hac . $i]);
             }
         }
     }
     $this->form->bind($post_parameters, $request->getFiles($this->form->getName()));
     if ($this->form->isValid()) {
         $isout = false;
         // Modifie les noms de chaque profil d'accès si un nom identifiant change et vérifie que chaque nom est unique
         if (!empty($this->physical_access_controllers)) {
             for ($i = 1; $i <= $this->nb_controller; $i++) {
                 foreach ($this->physical_access_controllers as $key => $value) {
                     $roomprofiles = array();
                     $controller_name = $key . $i;
                     // print  '<br/>------------------------------<br/>'.$controller_name.'<br />';
                     $params = $post_parameters[$controller_name];
                     $exname = ConfigurationHelper::getParameter($controller_name, 'controller_name');
                     $newname = $params['controller_name'];
                     // print 'ex-new : '.$exname.' - '.$newname.'<br />';
                     if ($exname != $newname) {
                         $roomprofiles = RoomprofilePeer::setAllNewIdentifierName($exname, $newname);
                     }
                     $this->checkError = ConfigurationHelper::checkControllersIdentifierName($controller_name, $newname, $this->nb_controller);
                     if (!$this->checkError['valid']) {
                         $isout = true;
                         break;
                     }
                     if (isset($roomprofiles)) {
                         if (!empty($roomprofiles)) {
                             foreach ($roomprofiles as $roomprofile) {
                                 $roomprofile->save();
                             }
                         }
                     }
                 }
                 if ($isout) {
                     break;
                 }
             }
         }
         // Modifie les noms de chaque contrôleur domotique si un nom identifiant change et vérifie que chaque nom est unique
         if (!empty($this->home_automation_controllers) && !$isout) {
             for ($i = 1; $i <= $this->nb_home_automation; $i++) {
                 foreach ($this->home_automation_controllers as $key => $value) {
                     $energyactions = array();
                     $controller_name = $key . $i;
                     // print  '<br/>------------------------------<br/>'.$controller_name.'<br />';
                     $params = $post_parameters[$controller_name];
                     $exname = ConfigurationHelper::getParameter($controller_name, 'controller_name');
                     $newname = $params['controller_name'];
                     // print 'ex-new : '.$exname.' - '.$newname.'<br />';
                     if ($exname != $newname) {
                         $energyactions = EnergyactionPeer::setAllNewIdentifierName($exname, $newname);
                     }
                     $this->checkError = ConfigurationHelper::checkAutomationsIdentifierName($controller_name, $newname, $this->nb_home_automation);
                     if (!$this->checkError['valid']) {
                         $isout = true;
                         break;
                     }
                     if (isset($energyactions)) {
                         if (!empty($energyactions)) {
                             foreach ($energyactions as $energyaction) {
                                 $energyaction->save();
                             }
                         }
                     }
                 }
                 if ($isout) {
                     break;
                 }
             }
         }
         if (!$isout) {
             $this->form->save();
             $this->saved = true;
         } else {
             $this->saved = false;
         }
     } else {
         $this->saved = false;
     }
     $this->setTemplate('home');
 }
 protected function execute($arguments = array(), $options = array())
 {
     $this->configuration = ProjectConfiguration::getApplicationConfiguration('frontend', 'prod', true);
     $this->context = sfContext::createInstance($this->configuration);
     $databaseManager = new sfDatabaseManager($this->configuration);
     ConfigurationHelper::load();
     $nb_controllers = ConfigurationHelper::get('number_of_physical_access');
     $reservations = ReservationPeer::doSelectPendingReservations($options['include-inactive'], $delayedTime);
     if (empty($reservations)) {
         $this->logSection('tempos', 'check - No reservations pending. Doing nothing.', 1024);
     } else {
         $this->logSection('tempos', sprintf('check - %d reservation(s) pending.', count($reservations)), 1024);
         $i = 0;
         foreach ($reservations as $reservation) {
             $roomprofile_id = $reservation->getRoomprofile()->getId();
             $roomprofile = RoomprofilePeer::doSelectFromId($roomprofile_id);
             $rp_controllername = $roomprofile->getConfiguredControllerName();
             $pac_infos = BasePhysicalAccessController::findPacFromNameIdentifier($rp_controllername);
             if (is_null($pac_infos) || empty($pac_infos)) {
                 $this->logSection('tempos', sprintf('check - Can\'t create a physical access controller for this reservation: id(%s)', $reservation->getId()), 1024);
                 continue;
             }
             $pac_name = $pac_infos['name'];
             // print 'pac_name: ';
             // var_dump($pac_name);
             $pac_id = $pac_infos['id'];
             // print 'pac_id: ';
             // var_dump($pac_id);
             $pac_selec = ConfigurationHelper::getParameter(null, $pac_name);
             // print 'pac_selec: ';
             // var_dump($pac_selec);
             $pac_conf = ConfigurationHelper::getNamespace($pac_selec . $pac_id);
             // print 'pac_conf: ';
             // var_dump($pac_conf);
             // var_dump($pac_infos);
             $pac = BasePhysicalAccessController::create($pac_selec, $pac_conf);
             // var_dump($pac);
             $delay = $pac->getParameter('delay');
             // print 'delay: ';
             // var_dump($delay);
             $pac->setVerbose($options['verbose']);
             $this->logSection('tempos', sprintf('check - Creating a physical access controller: %s', $pac->getName()), 1024);
             if (is_null($delay) || empty($delay)) {
                 $delay = 0;
             }
             $now = time();
             $delayedTime = time() + $delay * 60;
             // Need to add the delay in milliseconds to the time() function
             $this->logSection('tempos', sprintf('check - Checking reservations at: %s', strftime('%c', $now)), 1024);
             if ($delay > 0) {
                 $this->logSection('tempos', sprintf('check - There is a starting delay ! Need to start reservation %s minutes before the reservation date !', $delay), 1024);
                 $this->logSection('tempos', sprintf('check - Finally looking reservations at: %s', strftime('%c', $delayedTime)), 1024);
             }
             if ($delay > 0) {
                 $this->logSection('tempos', sprintf("check - \t(%d)\tBefore delay: %s", $i, $reservation->__toString()), 1024);
                 $reservation->updateDateWithDelay($delay);
                 $this->logSection('tempos', sprintf("check - \t(%d)\tAfter delay: %s", $i, $reservation->__toString()), 1024);
             } else {
                 $this->logSection('tempos', sprintf("check - \t(%d)\tReservation: %s", $i, $reservation->__toString()), 1024);
             }
             $results = $pac->sendReservation($reservation, $options['update-status']);
             if (empty($results)) {
                 $this->logSection('tempos', sprintf("check - \t\tSuccess."), 1024);
             } else {
                 foreach ($results as $result) {
                     $this->logSection('tempos', sprintf("check - \t\t%s: %s", $result['person'], $result['exception']->getMessage()), 1024, 'ERROR');
                 }
             }
             $i++;
         }
     }
 }
 public function configure()
 {
     $physical_access_controllers = BasePhysicalAccessController::getControllers();
     $home_automation_controllers = BaseHomeAutomationController::getControllers();
     $this->widgetSchema['number_of_physical_access'] = new sfWidgetFormInput();
     $this->validatorSchema['number_of_physical_access'] = new sfValidatorInteger(array('min' => 0, 'max' => $this->max_controllers, 'required' => true));
     $this->widgetSchema->setLabel('number_of_physical_access', 'Number of physical access controllers');
     if (!is_null($this->getOption('nb_pac'))) {
         $nb_pac = $this->getOption('nb_pac');
     } else {
         $nb_pac = ConfigurationHelper::getParameter(null, 'number_of_physical_access');
     }
     if ($nb_pac > $this->max_controllers) {
         $nb_pac = $this->max_controllers;
     }
     if (count($physical_access_controllers) > 0) {
         for ($i = 1; $i <= $nb_pac; $i++) {
             $this->widgetSchema['physical_access_controller' . $i] = new sfWidgetFormChoice(array('choices' => $physical_access_controllers));
             $this->validatorSchema['physical_access_controller' . $i] = new sfValidatorChoice(array('choices' => array_keys($physical_access_controllers), 'required' => false));
             $this->widgetSchema->setLabel('physical_access_controller' . $i, 'Physical Access Controller');
             foreach ($physical_access_controllers as $physical_access_controller => $name) {
                 $form = PhysicalAccessControllerConfigurationForm::create($physical_access_controller, null);
                 $labelName = $form->getPhysicalAccessController()->getName() . $i;
                 $this->embedForm($labelName, $form);
                 $this->widgetSchema->setLabel($labelName, $name);
             }
         }
     }
     $this->widgetSchema['number_of_home_automation'] = new sfWidgetFormInput();
     $this->validatorSchema['number_of_home_automation'] = new sfValidatorInteger(array('min' => 0, 'max' => $this->max_home_automation, 'required' => true));
     $this->widgetSchema->setLabel('number_of_home_automation', 'Number of home automation controllers');
     if (!is_null($this->getOption('nb_hac'))) {
         $nb_hac = $this->getOption('nb_hac');
     } else {
         $nb_hac = ConfigurationHelper::getParameter(null, 'number_of_home_automation');
     }
     if ($nb_hac > $this->max_home_automation) {
         $nb_hac = $this->max_home_automation;
     }
     if (count($home_automation_controllers) > 0) {
         for ($i = 1; $i <= $nb_hac; $i++) {
             $this->widgetSchema['home_automation_controller' . $i] = new sfWidgetFormChoice(array('choices' => $home_automation_controllers));
             $this->validatorSchema['home_automation_controller' . $i] = new sfValidatorChoice(array('choices' => array_keys($home_automation_controllers), 'required' => false));
             $this->widgetSchema->setLabel('home_automation_controller' . $i, 'Home automation controller');
             foreach ($home_automation_controllers as $home_automation_controller => $name) {
                 $form = HomeAutomationControllerConfigurationForm::create($home_automation_controller, null);
                 $labelName = $form->getHomeAutomationController()->getName() . $i;
                 $this->embedForm($labelName, $form);
                 $this->widgetSchema->setLabel($labelName, $name);
             }
         }
     }
     $this->addSubConfigurationForm('Network', 'Network');
     $this->addSubConfigurationForm('Email', 'Email');
     $this->addSubConfigurationForm('General', 'General');
     $this->addSubConfigurationForm('Rename', 'Rename');
     $this->addSubConfigurationForm('Backup', 'Backup');
     $this->addSubConfigurationForm('Print', 'Print');
     $this->setDefault('number_of_physical_access', 1);
     $this->setDefault('number_of_home_automation', 1);
     $this->setDefaults(ConfigurationHelper::get());
     $this->widgetSchema->setNameFormat('configuration[%s]');
     $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);
 }