/** * Unassign a ticket being coupled to a user or return an error message. * It will first check if the ticket is assigned, if this is indeed the case it will delete the 'assigned' entry. * @param $user_id the id of the user we want to unassign from the ticket * @param $ticket_id the id of the ticket. * @return A string, if unassigning succeedded "SUCCESS_UNASSIGNED" will be returned, else "NOT_ASSIGNED" will be returned. */ public static function unAssignTicket($user_id, $ticket_id) { $dbl = new DBLayer("lib"); //check if ticket is really assigned to that user if (Assigned::isAssigned($ticket_id, $user_id)) { $assignation = new Assigned(); $assignation->set(array('User' => $user_id, 'Ticket' => $ticket_id)); $assignation->delete(); return "SUCCESS_UNASSIGNED"; } else { return "NOT_ASSIGNED"; } }
public function run() { Assigned::truncate(); Assigned::create(['id' => '1', 'user_id' => '1', 'role_id' => '3']); Assigned::create(['id' => '2', 'user_id' => '2', 'role_id' => '2']); Assigned::create(['id' => '3', 'user_id' => '3', 'role_id' => '1']); // FOR TESTING PURPOSES Assigned::create(['id' => '4', 'user_id' => '4', 'role_id' => '2']); Assigned::create(['id' => '5', 'user_id' => '5', 'role_id' => '2']); Assigned::create(['id' => '6', 'user_id' => '6', 'role_id' => '2']); Assigned::create(['id' => '7', 'user_id' => '7', 'role_id' => '2']); Assigned::create(['id' => '8', 'user_id' => '8', 'role_id' => '1']); }
@endforeach </select> </div> <div class="col-md-4" align="center"> <br><br> <button type="button" class="btn btn-success" id="btn-add" onclick="select()"> Add <span class="glyphicon glyphicon-chevron-right"></span></button><br><br> <button type="button" class="btn btn-danger" id="btn-remove"><span class="glyphicon glyphicon-chevron-left"></span> Remove </button> <br><br> </div> <div class="col-md-4"> <strong>Currently Selected</strong> <select name="selectto" onchange"select()" id="select-to" multiple size="15" class="form-control" > @foreach($selected_users as $key2) <?php $roles = Assigned::where('user_id', $key2->id)->first(); if ($roles->role_id != 1) { echo $fullname2 = $key2->lastname . ", " . $key2->firstname; ?> <option value="{{ $key2->users_id }}" >{{ $fullname2 }}</option> <?php } ?> @endforeach </select> {{ Form::hidden('designation_id', "$designation_id"); }} {{ Form::hidden('members_selected', "", ['id'=>'members_selected']); }} </div> </div> <div class="table-responsive" align="right">
/** * get the user assigned to the ticket. * or return 0 in case not assigned. */ public function getAssigned() { $user_id = Assigned::getUserAssignedToTicket($this->getTId()); if ($user_id == "") { return 0; } else { return $user_id; } }
/** * This function is beign used to load info that's needed for the show_ticket page. * check if the person browsing this page is a mod/admin or the ticket creator himself, if not he'll be redirected to an error page. * if the $_GET['action'] var is set and the user executing is a mod/admin, it will try to execute the action. The actions here are: forwarding of a ticket, * assigning a ticket and unassigning a ticket. This function returns a lot of information that will be used by the template to show the ticket. Mods/admins will be able to * also see hidden replies to a ticket. * @author Daan Janssens, mentored by Matthew Lagoe */ function show_ticket() { //if logged in if (WebUsers::isLoggedIn() && isset($_GET['id'])) { $result['user_id'] = unserialize($_SESSION['ticket_user'])->getTUserId(); $result['ticket_id'] = filter_var($_GET['id'], FILTER_SANITIZE_NUMBER_INT); $target_ticket = new Ticket(); $target_ticket->load_With_TId($result['ticket_id']); if (Ticket_User::isMod(unserialize($_SESSION['ticket_user']))) { if (isset($_POST['action'])) { switch ($_POST['action']) { case "forward": $ticket_id = filter_var($_POST['ticket_id'], FILTER_SANITIZE_NUMBER_INT); $group_id = filter_var($_POST['group'], FILTER_SANITIZE_NUMBER_INT); $result['ACTION_RESULT'] = Ticket::forwardTicket($result['user_id'], $ticket_id, $group_id); break; case "assignTicket": $ticket_id = filter_var($_POST['ticket_id'], FILTER_SANITIZE_NUMBER_INT); $result['ACTION_RESULT'] = Ticket::assignTicket($result['user_id'], $ticket_id); break; case "unAssignTicket": $ticket_id = filter_var($_POST['ticket_id'], FILTER_SANITIZE_NUMBER_INT); $result['ACTION_RESULT'] = Ticket::unAssignTicket($result['user_id'], $ticket_id); break; } } } if ($target_ticket->getAuthor() == unserialize($_SESSION['ticket_user'])->getTUserId() || Ticket_User::isMod(unserialize($_SESSION['ticket_user']))) { $show_as_admin = false; if (Ticket_User::isMod(unserialize($_SESSION['ticket_user']))) { $show_as_admin = true; } $entire_ticket = Ticket::getEntireTicket($result['ticket_id'], $show_as_admin); Ticket_Log::createLogEntry($result['ticket_id'], unserialize($_SESSION['ticket_user'])->getTUserId(), 3); $result['ticket_tId'] = $entire_ticket['ticket_obj']->getTId(); $result['ticket_forwardedGroupName'] = $entire_ticket['ticket_obj']->getForwardedGroupName(); $result['ticket_forwardedGroupId'] = $entire_ticket['ticket_obj']->getForwardedGroupId(); $result['ticket_title'] = $entire_ticket['ticket_obj']->getTitle(); $result['ticket_timestamp'] = $entire_ticket['ticket_obj']->getTimestamp(); $result['ticket_status'] = $entire_ticket['ticket_obj']->getStatus(); $result['ticket_author'] = $entire_ticket['ticket_obj']->getAuthor(); $result['ticket_prioritytext'] = $entire_ticket['ticket_obj']->getPriorityText(); $result['ticket_priorities'] = Ticket::getPriorityArray(); $result['ticket_priority'] = $entire_ticket['ticket_obj']->getPriority(); $result['ticket_statustext'] = $entire_ticket['ticket_obj']->getStatusText(); $result['ticket_lastupdate'] = Gui_Elements::time_elapsed_string(Ticket::getLatestReply($result['ticket_id'])->getTimestamp()); $result['ticket_category'] = $entire_ticket['ticket_obj']->getCategoryName(); $webUser = new WebUsers(Assigned::getUserAssignedToTicket($result['ticket_tId'])); $result['ticket_assignedToText'] = $webUser->getUsername(); $result['ticket_assignedTo'] = Assigned::getUserAssignedToTicket($result['ticket_tId']); $result['ticket_replies'] = Gui_Elements::make_table($entire_ticket['reply_array'], array("getTReplyId", "getContent()->getContent", "getTimestamp", "getAuthor()->getExternId", "getAuthor()->getPermission", "getHidden"), array("tReplyId", "replyContent", "timestamp", "authorExtern", "permission", "hidden")); $i = 0; global $FILE_WEB_PATH; $result['FILE_WEB_PATH'] = $FILE_WEB_PATH; global $BASE_WEBPATH; $result['BASE_WEBPATH'] = $BASE_WEBPATH; foreach ($result['ticket_replies'] as $reply) { $webReplyUser = new WebUsers($reply['authorExtern']); $result['ticket_replies'][$i]['author'] = $webReplyUser->getUsername(); $i++; } if (Ticket_User::isMod(unserialize($_SESSION['ticket_user']))) { $result['isMod'] = "TRUE"; $result['statusList'] = Ticket::getStatusArray(); $result['sGroups'] = Gui_Elements::make_table_with_key_is_id(Support_Group::getAllSupportGroups(), array("getName"), "getSGroupId"); } $result['hasInfo'] = $target_ticket->hasInfo(); global $INGAME_WEBPATH; $result['ingame_webpath'] = $INGAME_WEBPATH; //get attachments $result['ticket_attachments'] = Ticket::getAttachments($result['ticket_id']); return $result; } else { //ERROR: No access! $_SESSION['error_code'] = "403"; header("Cache-Control: max-age=1"); header("Location: index.php?page=error"); throw new SystemExit(); } } else { //ERROR: not logged in! header("Cache-Control: max-age=1"); header("Location: index.php"); throw new SystemExit(); } }
/** * @return \yii\db\ActiveQuery */ public function getAssigneds() { return $this->hasMany(Assigned::className(), ['subject_id' => 'id']); }
public function store() { $user = new User(); $user->username = trim(Input::get('username')); $checkusername = User::where('username', $user->username)->first(); if (Input::get('role') == 1 && Input::get('email') == NULL) { // $user->email = "*****@*****.**"; } else { $user->email = trim(Input::get('email')); } $user->password = trim(Input::get('password')); $user->firstname = trim(Input::get('firstname')); $user->lastname = trim(Input::get('lastname')); $user->office_id = Input::get('office'); // The password confirmation will be removed from model // before saving. This field will be used in Ardent's // auto validation. $user->password_confirmation = Input::get('password_confirmation'); // Save if valid. Password field will be hashed before save $errorcheck = 0; $checkusername = 0; $users = new User(); $users = DB::table('users')->get(); foreach ($users as $userx) { if (strtoupper($userx->username) == strtoupper($user->username)) { $checkusername = 1; $errorcheck = 1; } } if ($checkusername != 0) { Session::put('username_error', 'Username is already in use.'); } $checkemail = 0; $users = new User(); $users = DB::table('users')->get(); foreach ($users as $userx) { if (strtoupper($userx->email) == strtoupper($user->email)) { $checkemail = 1; $errorcheck = 1; } } if (Input::get('role') == 1 && Input::get('email') == NULL) { } else { if ($checkemail != 0) { Session::put('email_error', 'Email is already in use.'); } } //Validations if (ctype_alnum($user->username) && strlen($user->username) >= 6) { } else { $errorcheck = 1; Session::put('username_error', 'Invalid username.'); } if (ctype_alpha(str_replace(array(' ', '-', '.'), '', $user->firstname))) { } else { $errorcheck = 1; Session::put('firstname_error', 'Invalid first name.'); } if (ctype_alpha(str_replace(array(' ', '-', '.'), '', $user->lastname))) { } else { $errorcheck = 1; Session::put('lastname_error', 'Invalid last name.'); } if (filter_var($user->email, FILTER_VALIDATE_EMAIL)) { } else { if (Input::get('role') == 1 && Input::get('email') == NULL) { } else { $errorcheck = 1; Session::put('email_error', 'Invalid email.'); } } if (ctype_alnum($user->password)) { if ($user->password != $user->password_confirmation) { $errorcheck = 1; Session::put('password_error', 'Password did not match with confirm password.'); } } else { $errorcheck = 1; Session::put('password_error', 'Invalid password.'); } if ($errorcheck == 0) { $user->save(); $username = $user->username; $assign = new Assigned(); $assign->role_id = Input::get('role'); $assign->user_id = $user->id; $assign->save(); $desig = new UserHasDesignation(); $desig->users_id = $user->id; $desig->designation_id = 0; $desig->save(); $notice = "User created successfully. "; // Redirect with success message, You may replace "Lang::get(..." for your custom message. return Redirect::action('UserController@viewUser')->with('notice', $notice); } else { Session::put('msg', 'Failed to create user.'); return Redirect::action('UserController@create')->withInput(Input::except('password')); } }
<input class="form-control" type="password" name="password" id="password" maxlength="255" > @if ( Session::get('password_error') ) <small><font color="red">{{ Session::get('password_error'); }} </font> </small> @endif </div> <div class="form-group"> <label for="password_confirmation">Confirm Password </label> <input class="form-control" type="password" name="password_confirmation" id="password_confirmation" maxlength="255"> </div> <div class="form-group"> <label for="role">Role *</label> <?php $assigned = Assigned::where('user_id', $id)->first(); if (NULL != Input::old('role')) { $role = Input::old('role'); } else { $role = $assigned->role_id; } ?> <select class="form-control" name="role" id="role" disabled> <option value="3" <?php if ($role == 3) { echo "selected"; } ?> >Admin</option> <option value="2" <?php