예제 #1
0
 public function view()
 {
     $tpl['DATE_SENT'] = $this->getDate();
     $tpl['MESSAGE'] = nl2br($this->message);
     $tpl['REASON'] = $this->getReason();
     $reporter = new \PHPWS_User($this->reporter_id);
     $offender = new \PHPWS_User($this->offender_id);
     $tpl['REPORTER'] = $reporter->getUsername();
     $tpl['OFFENDER'] = $offender->getUsername();
     $vars['QUESTION'] = "Ignoring this report will permanently delete it. Be sure you have dealt with those involved before removing it.\nAre you sure you want to ignore this report?";
     $vars['ADDRESS'] = \PHPWS_Text::linkAddress('properties', array('aop' => 'ignore_report', 'id' => $this->id), true);
     $vars['LINK'] = 'Ignore';
     $tpl['IGNORE'] = javascript('confirm', $vars);
     if (!$this->block) {
         $vars['QUESTION'] = "Ignoring this report will permanently delete it. Be sure you have dealt with those involved before removing it.\nAre you sure you want to ignore this report?";
         $vars['ADDRESS'] = \PHPWS_Text::linkAddress('properties', array('aop' => 'ignore_report', 'id' => $this->id), true);
         $vars['LINK'] = 'Ignore';
         $links[] = javascript('confirm', $vars);
         $vars['QUESTION'] = "Blocking a report will prevent the offender from logging in. Are you sure you want to do this?";
         $vars['ADDRESS'] = \PHPWS_Text::linkAddress('properties', array('aop' => 'block_report', 'id' => $this->id), true);
         $vars['LINK'] = 'Block';
         $links[] = javascript('confirm', $vars);
     } else {
         $vars['QUESTION'] = 'Removing this block will allow ' . $offender->getUsername() . ' access to roommates again. Are you sure you want to do this?';
         $vars['ADDRESS'] = \PHPWS_Text::linkAddress('properties', array('aop' => 'ignore_report', 'id' => $this->id), true);
         $vars['LINK'] = 'Remove Block';
         $links[] = javascript('confirm', $vars);
     }
     $links[] = '<a style="cursor : pointer" id="close-view">Close</a>';
     if ($this->block) {
         $tpl['BLOCK_REASON'] = $this->block_reason;
     }
     $tpl['LINKS'] = implode(' | ', $links);
     return \PHPWS_Template::process($tpl, 'properties', 'report_view.tpl');
 }
 /**
  * NB: All of the params are optional for compatibility with db->getObjects() .. Database is done wrong. Don't have time to fix it.
  * @param Internship $i
  * @param PHPWS_User $phpwsUser
  * @param int $timestamp
  * @param WorkflowState $fromState
  * @param WorkflowState $toState
  */
 public function __construct(Internship $i = null, PHPWS_User $phpwsUser = null, $timestamp = null, WorkflowState $fromState = null, WorkflowState $toState = null, $note = null)
 {
     if (!is_null($i)) {
         $this->id = 0;
         $this->internship_id = $i->getId();
         $this->username = $phpwsUser->getUsername();
         $this->timestamp = $timestamp;
         $this->from_state = $fromState->getName();
         $this->to_state = $toState->getName();
         $this->note = $note;
     }
 }
 /**
  * NB: All of the params are optional for compatibility with db->getObjects() .. Database is done wrong. Don't have time to fix it.
  * @param Internship $i
  * @param PHPWS_User $phpwsUser
  * @param int $timestamp
  * @param WorkflowState $fromState
  * @param WorkflowState $toState
  */
 public function __construct(Internship $i = null, \PHPWS_User $phpwsUser = null, $timestamp = null, WorkflowState $fromState = null, WorkflowState $toState = null, $note = null)
 {
     if (!is_null($i)) {
         $this->id = 0;
         $this->internship_id = $i->getId();
         $this->username = $phpwsUser->getUsername();
         $this->timestamp = $timestamp;
         // Strip namespace from start of from and to states, all four backspaces are required to escaping backslash
         $this->from_state = preg_replace("/Intern\\\\WorkflowState\\\\/", '', $fromState->getName());
         $this->to_state = preg_replace("/Intern\\\\WorkflowState\\\\/", '', $toState->getName());
         $this->note = $note;
     }
 }
예제 #4
0
 /**
  * Copies this floor object to a new term, then calls copy on all
  * 'this' floor's rooms
  *
  * Setting $assignments to 'true' causes the copy public function to copy
  * the assignments as well as the hall structure.
  *
  * @return bool False if unsuccessful.
  */
 public function copy($to_term, $hall_id, $assignments = false, $roles = false)
 {
     if (!$this->id) {
         return false;
     }
     //echo "in hms_floor, copying this floor id: $this->id <br>";
     // Create a clone of the current floor object
     // Set id to 0, set term, and save
     $new_floor = clone $this;
     $new_floor->reset();
     $new_floor->term = $to_term;
     $new_floor->residence_hall_id = $hall_id;
     $new_floor->f_movein_time_id = null;
     $new_floor->t_movein_time_id = null;
     $new_floor->rt_movein_time_id = null;
     try {
         $new_floor->save();
     } catch (Exception $e) {
         throw $e;
     }
     // Copy any roles related to this floor.
     if ($roles) {
         PHPWS_Core::initModClass("hms", "HMS_Permission.php");
         PHPWS_Core::initModClass("hms", "HMS_Role.php");
         // Get memberships by object instance.
         $membs = HMS_Permission::getUserRolesForInstance($this);
         // Add each user to new floor
         foreach ($membs as $m) {
             // Lookup the username
             $user = new PHPWS_User($m['user_id']);
             // Load role and add user to new instance
             $role = new HMS_Role();
             $role->id = $m['role'];
             $role->load();
             $role->addUser($user->getUsername(), get_class($new_floor), $new_floor->id);
         }
     }
     // Load all the rooms for this floor
     if (empty($this->_rooms)) {
         try {
             $this->loadRooms();
         } catch (Exception $e) {
             throw $e;
         }
     }
     /**
      * Rooms exist. Start making copies.
      * Further copying is needed at the room level.
      */
     if (!empty($this->_rooms)) {
         foreach ($this->_rooms as $room) {
             try {
                 $room->copy($to_term, $new_floor->id, null, $assignments);
             } catch (Exception $e) {
                 throw $e;
             }
         }
     }
 }
예제 #5
0
 public static function userForm(PHPWS_User $user, $message = NULL)
 {
     javascript('jquery');
     javascriptMod('users', 'generate');
     $form = new PHPWS_Form('edit-user');
     if ($user->getId() > 0) {
         $form->addHidden('user_id', $user->getId());
         $form->addSubmit('go', dgettext('users', 'Update User'));
     } else {
         $form->addSubmit('go', dgettext('users', 'Add User'));
     }
     $form->addHidden('action', 'admin');
     $form->addHidden('command', 'postUser');
     $form->addHidden('module', 'users');
     $form->addCheckbox('notify_user', 1);
     $form->setLabel('notify_user', dgettext('user', 'Notify user of account creation'));
     if (Current_User::allow('users', 'settings')) {
         $db = new PHPWS_DB('users_auth_scripts');
         $db->setIndexBy('id');
         $db->addColumn('id');
         $db->addColumn('display_name');
         $result = $db->select('col');
         if (PHPWS_Error::isError($result)) {
             PHPWS_Error::log($result);
         } else {
             if (!isset($result[$user->authorize])) {
                 $message['AUTHORIZE'] = dgettext('users', 'Warning: this user\'s authorization script is broken. Choose another and update.');
             }
             $form->addSelect('authorize', $result);
             $form->setMatch('authorize', $user->authorize);
             $form->setLabel('authorize', dgettext('users', 'Authorization'));
         }
     }
     if (!$user->id || $user->canChangePassword()) {
         $form->addText('username', $user->getUsername());
         $form->setRequired('username');
         $form->setLabel('username', dgettext('users', 'Username'));
         $form->addPassword('password1');
         $form->addPassword('password2');
         $form->setLabel('password1', dgettext('users', 'Password'));
         $form->addButton('create_pw', dgettext('users', 'Generate password'));
     } else {
         $form->addTplTag('USERNAME', $user->getUsername());
         $form->addTplTag('USERNAME_LABEL', '<strong>' . dgettext('users', 'Username') . '</strong>');
     }
     $form->addText('display_name', $user->display_name);
     $form->addText('email', $user->getEmail());
     $form->setSize('email', 30);
     $form->setRequired('email');
     $form->setLabel('email', dgettext('users', 'Email Address'));
     $form->setLabel('display_name', dgettext('users', 'Display name'));
     if (isset($tpl)) {
         $form->mergeTemplate($tpl);
     }
     $template = $form->getTemplate();
     $vars['action'] = 'admin';
     $vars['user_id'] = $user->id;
     if ($user->id) {
         $vars['command'] = 'setUserPermissions';
         $links[] = PHPWS_Text::secureLink(\Icon::show('permission') . ' ' . dgettext('users', 'Permissions'), 'users', $vars, null, dgettext('users', 'Permissions'), 'btn btn-default');
     }
     if (isset($links)) {
         $template['LINKS'] = implode(' | ', $links);
     }
     if (isset($message)) {
         foreach ($message as $tag => $error) {
             $template[strtoupper($tag) . '_ERROR'] = $error;
         }
     }
     if (!$user->id) {
         $template['JOIN_GROUPS'] = self::getJoinGroups();
     } else {
         $group_ids = $user->getGroups();
         if ($group_ids) {
             $db = Database::newDB();
             $t1 = $db->addTable('users_groups');
             $f1 = $t1->addField('name');
             $c1 = $t1->getFieldConditional('id', $group_ids, 'in');
             $c2 = $t1->getFieldConditional('user_id', 0);
             $db->stackConditionals($c1, $c2);
             while ($group = $db->selectColumn()) {
                 $template['members'][] = array('NAME' => $group);
             }
         }
         if (!isset($template['members'])) {
             $template['EMPTY_GROUP'] = dgettext('user', 'User not a member of any group');
         }
     }
     return PHPWS_Template::process($template, 'users', 'forms/userForm.tpl');
 }
예제 #6
0
 public function blockReport($report_id)
 {
     \PHPWS_Core::initModClass('properties', 'Message.php');
     \PHPWS_Core::initModClass('properties', 'Report.php');
     $report = new Report($report_id);
     $message = new Message($report->message_id);
     $user = new \PHPWS_User($message->from_user_id);
     $this->title = 'Block user:'******'module', 'properties');
     $form->addHidden('aop', 'block_post');
     $form->addHidden('report_id', $report->id);
     $form->addHidden('message_id', $message->id);
     $form->addTextarea('block_reason');
     $form->addSubmit('Block user');
     $tpl = $form->getTemplate();
     $this->content = \PHPWS_Template::process($tpl, 'properties', 'block.tpl');
 }
예제 #7
0
 public function copy($to_term, $assignments = FALSE, $roles = FALSE)
 {
     if (!$this->id) {
         return false;
     }
     // echo "In hms_residence_hall, copying this hall: $this->id <br>";
     // Create clone of current room object
     // Set id to 0, set term, and save
     $new_hall = clone $this;
     $new_hall->reset();
     $new_hall->id = 0;
     $new_hall->term = $to_term;
     try {
         $new_hall->save();
     } catch (Exception $e) {
         // rethrow it to the top level
         throw $e;
     }
     // Copy any roles related to this residence hall.
     if ($roles) {
         PHPWS_Core::initModClass("hms", "HMS_Permission.php");
         PHPWS_Core::initModClass("hms", "HMS_Role.php");
         // Get memberships by object instance.
         $membs = HMS_Permission::getUserRolesForInstance($this);
         // test($membs,1);
         // Add each user to new hall
         foreach ($membs as $m) {
             // Lookup the username
             $user = new PHPWS_User($m['user_id']);
             // Load role and add user to new instance
             $role = new HMS_Role();
             $role->id = $m['role'];
             $role->load();
             $role->addUser($user->getUsername(), get_class($new_hall), $new_hall->id);
         }
     }
     // Save successful, create new floors
     // Load all floors for this hall
     if (empty($this->_floors)) {
         try {
             $this->loadFloors();
         } catch (Exception $e) {
             throw $e;
         }
     }
     // Floors exist, start making copies
     if (!empty($this->_floors)) {
         foreach ($this->_floors as $floor) {
             try {
                 $floor->copy($to_term, $new_hall->id, $assignments, $roles);
             } catch (Exception $e) {
                 throw $e;
             }
         }
     }
 }