public static function getRole() { $userRole = array(); $use = User::find_by_id($_SESSION['user_ident']); $userRole = explode(",", $use->user_role); return $userRole; }
/** * Check whether a user is on probation. * @param int $userid * @return boolean TRUE if the user is on probation, FALSE if the user is not on probation */ function is_probationary_user($userid = null) { global $USER; // Check whether a new user threshold is in place or not. if (!is_using_probation()) { return false; } // Get the user's information if ($userid == null) { $user = $USER; } else { $user = new User(); $user->find_by_id($userid); } // Admins and staff get a free pass if ($user->get('admin') || $user->get('staff') || $user->is_institutional_admin() || $user->is_institutional_staff()) { return false; } // We actually store new user points in reverse. When your account is created, you get $newuserthreshold points, and // we decrease those when you do something good, and when it hits 0 you're no longer a new user. $userspoints = get_field('usr', 'probation', 'id', $user->get('id')); if ($userspoints > 0) { return true; } else { return false; } }
public static function current() { if (self::$current !== '') { return self::$current; } return self::$current = ($id = Session::getData('user_id')) ? User::find_by_id($id) : null; }
/** * Profile page */ function show($id) { $user = User::find_by_id($id); if (!$user) { throw new PageNotFoundException(); } return array('user' => $user); }
function __construct() { parent::__construct(); $this->view_data['core_settings'] = Setting::first(); if ($this->input->cookie('language') != "") { $language = $this->input->cookie('language'); } else { if (isset($this->view_data['language'])) { $language = $this->view_data['language']; } else { if (!empty($this->view_data['core_settings']->language)) { $language = $this->view_data['core_settings']->language; } else { $language = "english"; } } } $this->lang->load('application', $language); $this->lang->load('messages', $language); $this->lang->load('event', $language); $this->user = $this->session->userdata('user_id') ? User::find_by_id($this->session->userdata('user_id')) : FALSE; $this->client = $this->session->userdata('client_id') ? Client::find_by_id($this->session->userdata('client_id')) : FALSE; if ($this->client) { $this->theme_view = 'application_client'; } $this->view_data['datetime'] = date('Y-m-d H:i', time()); $this->view_data['sticky'] = Project::all(array('conditions' => 'sticky = 1')); $this->view_data['quotations_new'] = Quote::find_by_sql("select count(id) as amount from quotations where status='New'"); if ($this->user || $this->client) { $access = $this->user ? $this->user->access : $this->client->access; $access = explode(",", $access); if ($this->user) { $this->view_data['menu'] = Module::find('all', array('order' => 'sort asc', 'conditions' => array('id in (?) AND type = ?', $access, 'main'))); $this->view_data['widgets'] = Module::find('all', array('conditions' => array('id in (?) AND type = ?', $access, 'widget'))); } else { $this->view_data['menu'] = Module::find('all', array('order' => 'sort asc', 'conditions' => array('id in (?) AND type = ?', $access, 'client'))); } if ($this->user) { $update = User::find($this->user->id); } else { $update = Client::find($this->client->id); } $update->last_active = time(); $update->save(); if ($this->user) { $this->view_data['user_online'] = User::all(array('conditions' => array('last_active+(30 * 60) > ? AND status = ?', time(), "active"))); $this->view_data['client_online'] = Client::all(array('conditions' => array('last_active+(30 * 60) > ? AND inactive = ?', time(), "0"))); } $email = $this->user ? 'u' . $this->user->id : 'c' . $this->client->id; $this->view_data['messages_new'] = Privatemessage::find_by_sql("select count(id) as amount from privatemessages where `status`='New' AND recipient = '" . $email . "'"); $this->view_data['tickets_new'] = Ticket::find_by_sql("select count(id) as amount from tickets where `status`='New'"); } /*$this->load->database(); $sql = "select * FROM templates WHERE type='notes'"; $query = $this->db->query($sql); */ $this->view_data["note_templates"] = ""; //$query->result(); }
function create() { if ($_POST) { $config['upload_path'] = './files/media/'; $config['encrypt_name'] = TRUE; $config['allowed_types'] = '*'; $this->load->library('upload', $config); $this->load->helper('notification'); unset($_POST['userfile']); unset($_POST['file-name']); unset($_POST['send']); unset($_POST['_wysihtml5_mode']); unset($_POST['files']); $settings = Setting::first(); $client = Client::find_by_id($this->client->id); $user = User::find_by_id($settings->ticket_default_owner); $_POST['from'] = $client->firstname . ' ' . $client->lastname . ' - ' . $client->email; $_POST['company_id'] = $client->company->id; $_POST['client_id'] = $client->id; $_POST['user_id'] = $settings->ticket_default_owner; $_POST['queue_id'] = $settings->ticket_default_queue; $_POST['type_id'] = $settings->ticket_default_type; $_POST['status'] = $settings->ticket_default_status; $_POST['created'] = time(); $_POST['subject'] = htmlspecialchars($_POST['subject']); $ticket_reference = Setting::first(); $_POST['reference'] = $ticket_reference->ticket_reference; $ticket = Ticket::create($_POST); $new_ticket_reference = $_POST['reference'] + 1; $ticket_reference->update_attributes(array('ticket_reference' => $new_ticket_reference)); if (!$this->upload->do_upload()) { $error = $this->upload->display_errors('', ' '); $this->session->set_flashdata('message', 'error:' . $error); } else { $data = array('upload_data' => $this->upload->data()); $attributes = array('ticket_id' => $ticket->id, 'filename' => $data['upload_data']['orig_name'], 'savename' => $data['upload_data']['file_name']); $attachment = TicketHasAttachment::create($attributes); } if (!$ticket) { $this->session->set_flashdata('message', 'error:' . $this->lang->line('messages_create_ticket_error')); redirect('ctickets'); } else { $this->session->set_flashdata('message', 'success:' . $this->lang->line('messages_create_ticket_success')); if (isset($user->email) && isset($ticket->reference)) { send_ticket_notification($user->email, '[Ticket#' . $ticket->reference . '] - ' . $_POST['subject'], $_POST['text'], $ticket->id); } if (isset($client->email) && isset($ticket->reference)) { send_ticket_notification($client->email, '[Ticket#' . $ticket->reference . '] - ' . $_POST['subject'], $_POST['text'], $ticket->id); } redirect('ctickets/view/' . $ticket->id); } } else { $this->theme_view = 'modal'; $this->view_data['title'] = $this->lang->line('application_create_ticket'); $this->view_data['form_action'] = 'ctickets/create'; $this->content_view = 'tickets/client_views/_ticket'; } }
public static function init() { global $site; global $config; // IP Address $site['ip'] = getenv('REMOTE_ADDR'); if (getenv('HTTP_X_FORWARDED_FOR')) { $site['ip'] = getenv('HTTP_X_FORWARDED_FOR'); } if (isset($config['dev_sql']) && $config['dev_sql']) { $date = date("Y-m-d H:i:s"); file_put_contents("logs/sql.log", "[{$date}] - {$site['ip']} - {$_SERVER['REQUEST_METHOD']} {$_SERVER['REQUEST_URI']}\r\n", FILE_APPEND); } // Login if (isset($_SESSION['user'])) { $user = User::find_by_id($_SESSION['user']); if ($user) { if ($user->suspended) { self::Flash("error", "Your account has been suspended"); unset($_SESSION['user']); } elseif ($user->activated == 0) { self::Flash("error", "Your account has not been activated"); unset($_SESSION['user']); } else { $site['user'] = $user; } } else { unset($_SESSION['user']); } } // Cookie Login if (!isset($site['user']) && isset($_COOKIE['userkey'])) { $cookie = $_COOKIE['userkey']; if ($cookie) { $cookie = mysql_real_escape_string($cookie); $user = User::find("users.cookie = '{$cookie}'", null, false, 1); if ($user) { if ($user->suspended) { self::Flash("error", "Your account has been suspended"); setcookie("userkey", null, -3600, "/"); } elseif ($user->activated == 0) { self::Flash("error", "Your account has not been activated"); setcookie("userkey", null, -3600, "/"); } else { $site['user'] = $user; $_SESSION['user'] = $user->id; setcookie("userkey", $user->cookie, time() + 31536000, "/"); } } } } $site['dev'] = $config['dev']; // Maintain visit history if (!isset($_SESSION['history'])) { $_SESSION['history'] = array(); } array_unshift($_SESSION['history'], $_SERVER["REQUEST_URI"]); }
public function __construct() { parent::__construct(); if (in_array($this->uri->rsegments(2, 0), array('edit', 'update', 'destroy'))) { if (!(($id = $this->uri->rsegments(3, 0)) && ($this->user = User::find_by_id($id)))) { return redirect_message(array('admin', $this->get_class()), array('_flash_message' => '找不到該筆資料。')); } } $this->add_tab('使用者列表', array('href' => base_url('admin', $this->get_class()), 'index' => 1)); }
public function excluirAction($user_id = null) { if (is_numeric($user_id)) { $user = User::find_by_id($user_id); if (!is_null($user)) { $user->delete(); $this->view->setVar('users', User::all()); } } }
public static function render_instance(BlockInstance $instance, $editing = false) { global $USER; require_once get_config('docroot') . 'lib/view.php'; $configdata = $instance->get('configdata'); // this will make sure to unserialize it for us $configdata['viewid'] = $instance->get('view'); $view = new View($configdata['viewid']); $group = $view->get('group'); $result = ''; $artefactid = isset($configdata['artefactid']) ? $configdata['artefactid'] : null; if ($artefactid) { $artefact = $instance->get_artefact_instance($configdata['artefactid']); if (!file_exists($artefact->get_path())) { return ''; } $urlbase = get_config('wwwroot'); // edit view doesn't use subdomains, neither do groups if (get_config('cleanurls') && get_config('cleanurlusersubdomains') && !$editing && empty($group)) { $viewauthor = new User(); $viewauthor->find_by_id($view->get('owner')); $viewauthorurlid = $viewauthor->get('urlid'); if ($urlallowed = !is_null($viewauthorurlid) && strlen($viewauthorurlid)) { $urlbase = profile_url($viewauthor) . '/'; } } // Send the current language to the pdf viewer $language = current_language(); $language = str_replace('_', '-', substr($language, 0, substr_count($language, '_') > 0 ? 5 : 2)); if ($language != 'en' && !file_exists(get_config('docroot') . 'artefact/file/blocktype/pdf/js/pdfjs/web/locale/' . $language . '/viewer.properties')) { // In case the language file exists as a string with both lower and upper case, eg fr_FR we test for this $language = substr($language, 0, 2) . '-' . strtoupper(substr($language, 0, 2)); if (!file_exists(get_config('docroot') . 'artefact/file/blocktype/pdf/js/pdfjs/web/locale/' . $language . '/viewer.properties')) { // In case we fail to find a language of 5 chars, eg pt_BR (Portugese, Brazil) we try the 'parent' pt (Portugese) $language = substr($language, 0, 2); if ($language != 'en' && !file_exists(get_config('docroot') . 'artefact/file/blocktype/pdf/js/pdfjs/web/locale/' . $language . '/viewer.properties')) { $language = 'en-GB'; } } } $result = '<iframe src="' . $urlbase . 'artefact/file/blocktype/pdf/viewer.php?editing=' . $editing . '&ingroup=' . !empty($group) . '&file=' . $artefactid . '&lang=' . $language . '&view=' . $instance->get('view') . '" width="100%" height="500" frameborder="0"></iframe>'; require_once get_config('docroot') . 'artefact/comment/lib.php'; require_once get_config('docroot') . 'lib/view.php'; $view = new View($configdata['viewid']); list($commentcount, $comments) = ArtefactTypeComment::get_artefact_comments_for_view($artefact, $view, $instance->get('id'), true, $editing); } $smarty = smarty_core(); if ($artefactid) { $smarty->assign('commentcount', $commentcount); $smarty->assign('comments', $comments); } $smarty->assign('html', $result); return $smarty->fetch('blocktype:pdf:pdfrender.tpl'); }
public static function init() { if (isset($_COOKIE['SESSID'])) { if (UserSession::exists(array('session_id' => $_COOKIE['SESSID']))) { $session = User::find_by_id(UserSession::find_by_session_id($_COOKIE['SESSID'])->user_id); session_id($_COOKIE['SESSID']); self::set($session); } else { setcookie("SESSID", "", -1); self::set(-1); } session_start(); } UserSession::delete_all(array('conditions' => array('expiration < ?', Utils::tps()))); }
/** * Attempt to authenticate user * * @param object $user As returned from the usr table * @param string $password The password being used for authentication * @return bool True/False based on whether the user * authenticated successfully * @throws AuthUnknownUserException If the user does not exist */ public function authenticate_user_account($user, $password) { $this->must_be_ready(); $result = $this->validate_password($password, $user->password, $user->salt); // If result == 1, password is correct // If result > 1, password is correct but using old settings, should be changed if ($result > 1) { if ($user->passwordchange != 1) { $userobj = new User(); $userobj->find_by_id($user->id); $this->change_password($userobj, $password); $user->password = $userobj->password; $user->salt = $userobj->salt; } } return $result > 0; }
public function create($group_id = null) { $group = self::load_group($group_id); if ($this->post) { $added = false; foreach ($_POST['users'] as $id) { $user = User::find_by_id($id); if ($user) { $user_group = new UserGroup(); $user_group->user_id = $user->id; $user_group->group_id = $group->id; if ($user_group->save()) { $added = true; } } } if ($added) { Site::Flash("notice", "The users have been added to the group"); } Redirect("admin/groups/{$group->id}"); } $group_users = array(); foreach ($group->users() as $user) { $group_users[] = $user->id; } $users = array(); $all_users = User::find_all("", "nickname ASC"); foreach ($all_users as $user) { if (!in_array($user->id, $group_users)) { $users[] = $user; } } if (count($users) == 0) { Site::Flash("error", "There are no more users to add."); Redirect("admin/groups/{$group->id}"); } $this->assign("users", $users); $this->assign("group", $group); $this->title = "Add Users"; $this->render("user_group/create.tpl"); }
/** * activate * * @return void * @author Mathew **/ public function activate($id, $code = false) { if ($code !== FALSE) { $user = User::find_by_activation_code($code); if (!$user) { return FALSE; } $data = array('activation_code' => NULL, 'active' => 1); $user->update_attributes($data); } else { $user = User::find_by_id($id); $data = array('activation_code' => NULL, 'active' => 1); $user->update_attributes($data); } if ($user->is_valid()) { return TRUE; } if ($user->is_invalid()) { return FALSE; } }
function filter($userid = FALSE, $year = FALSE, $month = FALSE) { $this->view_data['userlist'] = User::find('all', array('conditions' => array('status = ?', 'active'))); $this->view_data['username'] = User::find_by_id($userid); $this->view_data['user_id'] = $userid; $this->view_data['year'] = $year; $this->view_data['month'] = $month; $search = ""; $stats_search = ""; if ($userid) { $search .= "user_id = {$userid} and "; $stats_search = " AND user_id = {$userid} "; } if ($month && $year) { $search .= "date >= '{$year}-{$month}-01' and date <= '{$year}-{$month}-31'"; } else { $search .= "date >= '{$year}-01-01' and date <= '{$year}-12-31'"; } //statistic $graph_month = $month != 0 ? $month : date('m'); if ($month == 0) { $lastday_in_month = strtotime($year . "-12-31"); $firstday_in_month = strtotime($year . "-01-01"); $this->view_data['days_in_this_month'] = 12; $this->view_data['expenses_this_month'] = Expense::count(array('conditions' => 'UNIX_TIMESTAMP(`date`) <= ' . $lastday_in_month . ' and UNIX_TIMESTAMP(`date`) >= ' . $firstday_in_month . $stats_search)); $this->view_data['expenses_owed_this_month'] = Expense::find_by_sql('select sum(value) AS "owed" from expenses where UNIX_TIMESTAMP(`date`) >= "' . $firstday_in_month . '" AND UNIX_TIMESTAMP(`date`) <= "' . $lastday_in_month . '"' . $stats_search); $this->view_data['expenses_due_this_month_graph'] = Expense::find_by_sql('select sum(value) AS "owed", MONTH(`date`) as `date` from expenses where UNIX_TIMESTAMP(`date`) >= "' . $firstday_in_month . '" AND UNIX_TIMESTAMP(`date`) <= "' . $lastday_in_month . '"' . $stats_search . ' Group By MONTH(`date`)'); } else { $days_in_this_month = days_in_month($graph_month, $year); $lastday_in_month = strtotime($year . "-" . $graph_month . "-" . $days_in_this_month); $firstday_in_month = strtotime($year . "-" . $graph_month . "-01"); $this->view_data['days_in_this_month'] = $days_in_this_month; $this->view_data['expenses_this_month'] = Expense::count(array('conditions' => 'UNIX_TIMESTAMP(`date`) <= ' . $lastday_in_month . ' and UNIX_TIMESTAMP(`date`) >= ' . $firstday_in_month . $stats_search)); $this->view_data['expenses_owed_this_month'] = Expense::find_by_sql('select sum(value) AS "owed" from expenses where UNIX_TIMESTAMP(`date`) >= "' . $firstday_in_month . '" AND UNIX_TIMESTAMP(`date`) <= "' . $lastday_in_month . '"' . $stats_search); $this->view_data['expenses_due_this_month_graph'] = Expense::find_by_sql('select sum(value) AS "owed", `date` from expenses where UNIX_TIMESTAMP(`date`) >= "' . $firstday_in_month . '" AND UNIX_TIMESTAMP(`date`) <= "' . $lastday_in_month . '"' . $stats_search . ' Group By `date`'); } $this->view_data['expenses'] = Expense::find('all', array('conditions' => array("{$search}"))); $this->content_view = 'expenses/all'; }
public function show($id = null) { if (isset($_GET['id'])) { $id = $_GET['id']; } if (!$id) { Error404(); } $payment = PaymentTransaction::find_by_id($id); if (!$payment) { Error404(); } $cart = Cart::find_by_id($payment->cart_id); if ($cart) { $user = User::find_by_id($cart->user_id); $this->assign("user", $user); $this->assign("cart", $cart); } $this->assign("payment", $payment); $this->title = "Payment {$payment->id}"; $this->render("paymenttransaction/show.tpl"); }
public static function notify($user_id, $group_id) { $group = Group::find_by_id($group_id); if ($group == null) { return; } // Error getting group $user = User::find_by_id($user_id); if ($user == null) { return; } // Error getting user $to = $user->get_email(); $subject = wordwrap("You've been added to '" . $group->get_name() . "' on CodeChat!"); $message = "<html><body>"; $message .= "<p>To start chatting with your new group, just visit <a href='http://wwwp.cs.unc.edu/Courses/comp426-f15/users/dbobbitt/Codiad/workspace/cs426/Final/Frontend/main.php'>www.codechat.com</a>!</p>"; $message .= "<br><br>Happy coding!"; $message .= "</body></html>"; $headers = "From: no-reply@codechat.com\r\n"; $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; mail($to, $subject, $message, $headers); }
<?php require_once "../includes/database.php"; require_once "../includes/user.php"; $record = User::find_by_id(1); echo $user->full_name(); echo "<hr />"; // $user_set = User::find_all(); // while ($user = $database->fetch_array($user_set)) { // echo "User: "******"<br />"; // echo "Name: ". $user['first_name'] . " " . $user['last_name'] ."<br /><br />"; // }
<?php include "includes/header.php"; if (!$session->is_signed_in()) { redirect_to("login.php"); } if (empty($_GET['id'])) { redirect_to("users.php"); } else { $user = User::find_by_id($_GET['id']); } if (isset($_POST['update'])) { $user->username = $_POST['username']; $user->first_name = $_POST['first_name']; $user->last_name = $_POST['last_name']; $user->password = $_POST['password']; if (empty($_FILES['user_image']['name'])) { $user->save(); } else { $user->set_file($_FILES['user_image']); $user->save_user_and_image(); } print_r($_FILES); // redirect_to("edit_user.php?id=".$user->id ); } ?> <!-- Navigation --> <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation"> <!-- Brand and toggle get grouped for better mobile display --> <?php
function auth_register_submit(Pieform $form, $values) { global $SESSION; safe_require('auth', 'internal'); $values['key'] = get_random_key(); $values['lang'] = $SESSION->get('lang'); // If the institution requires approval, mark the record as pending // @todo the expiry date should be configurable if ($confirm = get_config('requireregistrationconfirm') || get_field('institution', 'registerconfirm', 'name', $values['institution'])) { if (isset($values['authtype']) && $values['authtype'] != 'internal') { $authinstance = get_record('auth_instance', 'institution', $values['institution'], 'authname', $values['authtype'] ? $values['authtype'] : 'internal'); $auth = AuthFactory::create($authinstance->id); $confirm = !$auth->weautocreateusers; } if ($confirm) { $values['pending'] = 1; $values['expiry'] = db_format_timestamp(time() + 86400 * 14); // now + 2 weeks } else { $values['pending'] = 0; $values['expiry'] = db_format_timestamp(time() + 86400); } } else { $values['pending'] = 0; $values['expiry'] = db_format_timestamp(time() + 86400); } if (function_exists('local_register_submit')) { local_register_submit($values); } try { if (!record_exists('usr_registration', 'email', $values['email'])) { insert_record('usr_registration', $values); } else { update_record('usr_registration', $values, array('email' => $values['email'])); } $user = (object) $values; $user->admin = 0; $user->staff = 0; // If the institution requires approval, notify institutional admins. if ($confirm) { $fullname = sprintf("%s %s", trim($user->firstname), trim($user->lastname)); $institution = new Institution($values['institution']); $pendingregistrationslink = sprintf("%sadmin/users/pendingregistrations.php?institution=%s", get_config('wwwroot'), $values['institution']); // list of admins for this institution if (count($institution->admins()) > 0) { $admins = $institution->admins(); } else { // use site admins if the institution doesn't have any $admins = get_column('usr', 'id', 'admin', 1, 'deleted', 0); } require_once get_config('libroot') . 'pieforms/pieform/elements/expiry.php'; $expirytime = pieform_element_expiry_get_expiry_from_seconds(get_config('defaultregistrationexpirylifetime')); if ($expirytime == null) { $expirystring = get_config('defaultregistrationexpirylifetime') . ' ' . get_string('seconds', 'performance'); } else { if ($expirytime['units'] == 'noenddate') { $expirystring = get_string('element.expiry.noenddate', 'pieforms'); } else { $expirystring = $expirytime['number'] . ' ' . get_string('element.expiry.' . $expirytime['units'], 'pieforms'); } } // email each admin // @TODO Respect the notification preferences of the admins. foreach ($admins as $admin) { $adminuser = new User(); $adminuser->find_by_id($admin); email_user($adminuser, null, get_string('pendingregistrationadminemailsubject', 'auth.internal', $institution->displayname, get_config('sitename')), get_string('pendingregistrationadminemailtext', 'auth.internal', $adminuser->firstname, $institution->displayname, $pendingregistrationslink, $expirystring, $fullname, $values['email'], $values['reason'], get_config('sitename')), get_string('pendingregistrationadminemailhtml', 'auth.internal', $adminuser->firstname, $institution->displayname, $pendingregistrationslink, $pendingregistrationslink, $expirystring, $fullname, $values['email'], $values['reason'], get_config('sitename'))); } email_user($user, null, get_string('approvalemailsubject', 'auth.internal', get_config('sitename')), get_string('approvalemailmessagetext', 'auth.internal', $values['firstname'], get_config('sitename'), get_config('sitename')), get_string('approvalemailmessagehtml', 'auth.internal', $values['firstname'], get_config('sitename'), get_config('sitename'))); $_SESSION['registeredokawaiting'] = true; } else { if (isset($values['authtype']) && $values['authtype'] == 'browserid') { redirect('/register.php?key=' . $values['key']); } else { email_user($user, null, get_string('registeredemailsubject', 'auth.internal', get_config('sitename')), get_string('registeredemailmessagetext', 'auth.internal', $values['firstname'], get_config('sitename'), get_config('wwwroot'), $values['key'], get_config('sitename')), get_string('registeredemailmessagehtml', 'auth.internal', $values['firstname'], get_config('sitename'), get_config('wwwroot'), $values['key'], get_config('wwwroot'), $values['key'], get_config('sitename'))); } // Add a marker in the session to say that the user has registered $_SESSION['registered'] = true; } } catch (EmailException $e) { log_warn($e); die_info(get_string('registrationunsuccessful', 'auth.internal')); } catch (SQLException $e) { log_warn($e); die_info(get_string('registrationunsuccessful', 'auth.internal')); } redirect($values['goto']); }
public function change_identity_to($userid) { $user = new User(); $user->find_by_id($userid); if (!$this->is_admin_for_user($user)) { throw new AccessDeniedException(get_string('loginasdenied', 'admin')); } $olduser = $this->get('parentuser'); if (!is_null($olduser)) { throw new UserException(get_string('loginastwice', 'admin')); } $olduser = new StdClass(); $olduser->id = $this->get('id'); $olduser->name = display_name($this, null, true); $this->reloadLiveUser($userid); $this->set('parentuser', $olduser); }
/** * Will check to see if the session's user_id is set and if so then it will * set a flag to true to show that that user is logged in with that particular * id * This method is very important since, without it any reference to the class * variables when not on the login page * * Now when this method is run, which happens as a __constuct and therefore at * the start of every file, it will use the DatabaseObject to find a user from * the database and then return that User object to a private Session class * variable so that I can use it to log the username or full name, anything the * User class object offers. * * This is final what I wanted because I did not want the username to be in * the public realm. * @return [type] [description] */ private function check_if_login() { if (isset($_SESSION['user_id'])) { $this->user_id = $_SESSION['user_id']; $this->user = User::find_by_id($this->user_id); $this->logged_in = true; } else { unset($this->user_id); $this->logged_in = false; } }
public static function getSubscriptionsVideos($userId, $amount = 'nope') { $videos = []; $user = User::find_by_id($userId); $sub_array = $user->getSubscribedChannelsAsList(); if (empty($sub_array)) { return []; //No sub } $sub_array = array_map(function ($v) { return "'{$v}'"; }, $sub_array); $subs = '(' . implode(', ', $sub_array) . ')'; if ($amount != 'nope') { $vidsToAdd = Video::find_by_sql("SELECT * FROM videos WHERE visibility=2 AND poster_id IN " . $subs . " ORDER BY timestamp DESC LIMIT " . $amount); } else { $vidsToAdd = Video::find_by_sql("SELECT * FROM videos WHERE visibility=2 AND poster_id IN " . $subs . " ORDER BY timestamp DESC"); } return $vidsToAdd; }
/** * Create user * * @param object $user stdclass or User object for the usr table * @param array $profile profile field/values to set * @param string $institution Institution the user should joined to * @param stdclass $remoteauth authinstance record for a remote authinstance * @param string $remotename username on the remote site * @return integer id of the new user */ function create_user($user, $profile = array(), $institution = null, $remoteauth = null, $remotename = null) { db_begin(); if ($user instanceof User) { $user->create(); $user->quota_init(); $user->commit(); $user = $user->to_stdclass(); } else { $user->ctime = db_format_timestamp(time()); if (empty($user->quota)) { $user->quota = get_config_plugin('artefact', 'file', 'defaultquota'); } $user->id = insert_record('usr', $user, 'id', true); } // Bypass access check for 'copynewuser' institution/site views, because this user may not be logged in yet $user->newuser = true; if (isset($user->email) && $user->email != '') { set_profile_field($user->id, 'email', $user->email); } if (isset($user->firstname) && $user->firstname != '') { set_profile_field($user->id, 'firstname', $user->firstname); } if (isset($user->lastname) && $user->lastname != '') { set_profile_field($user->id, 'lastname', $user->lastname); } foreach ($profile as $k => $v) { if (in_array($k, array('firstname', 'lastname', 'email'))) { continue; } set_profile_field($user->id, $k, $v); } if (!empty($institution) && $institution != 'mahara') { if (is_string($institution)) { $institution = new Institution($institution); } if ($institution->name != 'mahara') { $institution->addUserAsMember($user); // uses $user->newuser } } if (!empty($remoteauth) && $remoteauth->authname != 'internal') { if (isset($remotename) && strlen($remotename) > 0) { $un = $remotename; } else { $un = $user->username; } delete_records('auth_remote_user', 'authinstance', $user->authinstance, 'remoteusername', $un); insert_record('auth_remote_user', (object) array('authinstance' => $user->authinstance, 'remoteusername' => $un, 'localusr' => $user->id)); } // Copy site views to the new user's profile $checkviewaccess = !$user->newuser; $userobj = new User(); $userobj->find_by_id($user->id); $userobj->copy_views(get_column('view', 'id', 'institution', 'mahara', 'copynewuser', 1), $checkviewaccess); handle_event('createuser', $user); db_commit(); return $user->id; }
function edituser_institution_submit(Pieform $form, $values) { $user = new User(); if (!$user->find_by_id($values['id'])) { return false; } $userinstitutions = $user->get('institutions'); global $USER, $SESSION; foreach ($userinstitutions as $i) { if ($USER->can_edit_institution($i->institution)) { if (isset($values[$i->institution . '_submit'])) { $newuser = (object) array('usr' => $user->id, 'institution' => $i->institution, 'ctime' => db_format_timestamp($i->ctime), 'studentid' => $values[$i->institution . '_studentid'], 'staff' => (int) ($values[$i->institution . '_staff'] == 'on'), 'admin' => (int) ($values[$i->institution . '_admin'] == 'on')); if ($values[$i->institution . '_expiry']) { $newuser->expiry = db_format_timestamp($values[$i->institution . '_expiry']); } db_begin(); delete_records('usr_institution', 'usr', $user->id, 'institution', $i->institution); insert_record('usr_institution', $newuser); if ($newuser->admin) { activity_add_admin_defaults(array($user->id)); } handle_event('updateuser', $user->id); db_commit(); $SESSION->add_ok_msg(get_string('userinstitutionupdated', 'admin', $i->displayname)); break; } else { if (isset($values[$i->institution . '_remove'])) { if ($user->id == $USER->id) { $USER->leave_institution($i->institution); } else { $user->leave_institution($i->institution); } $SESSION->add_ok_msg(get_string('userinstitutionremoved', 'admin', $i->displayname)); // Institutional admins can no longer access this page // if they remove the user from the institution, so // send them back to user search. if (!$USER->get('admin')) { if (!$USER->is_institutional_admin()) { redirect(get_config('wwwroot')); } redirect('/admin/users/search.php'); } break; } } } } if (isset($values['add']) && $USER->get('admin') && (empty($userinstitutions) || get_config('usersallowedmultipleinstitutions'))) { if ($user->id == $USER->id) { $USER->join_institution($values['addinstitution']); $USER->commit(); $userinstitutions = $USER->get('institutions'); } else { $user->join_institution($values['addinstitution']); $userinstitutions = $user->get('institutions'); } $SESSION->add_ok_msg(get_string('userinstitutionjoined', 'admin', $userinstitutions[$values['addinstitution']]->displayname)); } redirect('/admin/users/edit.php?id=' . $user->id); }
<!DOCTYPE html> <html lang="en"> <?php require_once 'includes/initialize.php'; ?> <?php //Load Session details... if (!$session->is_logged_in()) { session_start(); } if (!isset($_SESSION['user_id'])) { redirect_to('login.php?msg=Please Log-in first.'); } $user = User::find_by_id($_SESSION['user_id']); $path = 'assets/images/profile_pic/' . $user->profile_pic; echo envapi_get_html_for_reg_user('176644-3EaSQ9JhWGaxqDH2EJ91XS3smNIPajiD', $user->first_name, $user->last_name, $path, false, "HI"); ?> <?php //Count the no. of unread messages... $count = User::count_unread_messages($_SESSION['user_id']); ?> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="description" content="Neon Admin Panel" />
$sql_proprietate .= "DataActualizare,SuprafataUtila,SuprafataConstruita,OfertaSpeciala) VALUES "; $sql_dotare = "INSERT INTO DotareApartament (idApartament,idDotare) VALUES "; $sql_foto = "INSERT INTO Foto (idProprietate, NumeFisier, Tip, Marime, Detalii, Ordin, Schita) VALUES "; $sql = "SELECT * FROM Oferta WHERE (Exportat<>1 OR Exportat=NULL)"; $oferte = Oferta::find_by_sql($sql); //$oferta=array_shift($oferte); $td = 0; $ti = 0; $tu = 0; $sync = 0; $insert = 0; foreach ($oferte as $oferta) { $sync++; $apartament = Apartament::find_by_id($oferta->id); $client = Client::find_by_id($apartament->idClient); $agent = User::find_by_id($client->idUtilizator); $sql = "SELECT * FROM Proprietate WHERE CodBazaDate={$oferta->id}"; $update = 0; $result = mysql_query($sql, $conexiune2); if ($row = mysql_fetch_array($result)) { $update = 1; $idProprietate = $row["id"]; } if ($update) { $td1 = time(); $sql = "DELETE FROM DotareApartament WHERE idApartament={$idProprietate}"; $result = execute_querry($sql, $conexiune2); //$sql="ALTER TABLE DotareApartament AUTO_INCREMENT = 1"; //$result=execute_querry($sql, $conexiune2); $sql = "DELETE FROM Foto WHERE idProprietate={$idProprietate}"; $result = execute_querry($sql, $conexiune2);
/** * Get all views & collections for a (user,group), grouped * by their accesslists as defined by the accessconf column * * @param integer $owner * @param integer $group * * @return array */ public static function get_accesslists($owner = null, $group = null, $institution = null) { require_once 'institution.php'; if (!is_null($owner) && !is_array($owner) && $owner > 0) { $ownerobj = new User(); $ownerobj->find_by_id($owner); } $data = array(); list($data['collections'], $data['views']) = self::get_views_and_collections($owner, $group, $institution); // Remember one representative viewid in each collection $viewindex = array(); // Add strings to describe startdate/stopdate access overrides foreach ($data['collections'] as &$c) { $view = current($c['views']); $viewindex[$view['id']] = array('type' => 'collections', 'id' => $c['id']); $c['access'] = self::access_override_description($view); $c['viewid'] = $view['id']; } foreach ($data['views'] as &$v) { $viewindex[$v['id']] = array('type' => 'views', 'id' => $v['id']); $v['access'] = self::access_override_description($v); $v['viewid'] = $v['id']; } if (empty($viewindex)) { return $data; } // Get view_access records, apart from those with visible = 0 (system access records) $accessgroups = get_records_sql_array(' SELECT va.*, g.grouptype, g.name, g.urlid FROM {view_access} va LEFT OUTER JOIN {group} g ON (g.id = va.group AND g.deleted = 0) WHERE va.view IN (' . join(',', array_keys($viewindex)) . ') AND va.visible = 1 ORDER BY va.view, va.accesstype, g.grouptype, va.role, g.name, va.group, va.usr', array()); if (!$accessgroups) { return $data; } if (!function_exists('is_probationary_user')) { require_once get_config('libroot') . 'antispam.php'; } foreach ($accessgroups as $access) { // remove 'Public' from the list if the owner isn't allowed to have them if ($access->accesstype == 'public' && (get_config('allowpublicviews') != 1 || isset($ownerobj) && !$ownerobj->institution_allows_public_views() || isset($ownerobj) && is_probationary_user($ownerobj->id))) { continue; } $vi = $viewindex[$access->view]; // Just count secret urls. if ($access->token) { if (!isset($data[$vi['type']][$vi['id']]['secreturls'])) { $data[$vi['type']][$vi['id']]['secreturls'] = 0; } $data[$vi['type']][$vi['id']]['secreturls']++; continue; } $key = null; if ($access->usr) { $access->accesstype = 'user'; $access->id = $access->usr; } else { if ($access->group) { $access->accesstype = 'group'; $access->id = $access->group; if ($access->role) { $access->roledisplay = get_string($access->role, 'grouptype.' . $access->grouptype); } $access->groupurl = group_homepage_url((object) array('id' => $access->group, 'urlid' => $access->urlid)); } else { if ($access->institution) { $access->accesstype = 'institution'; $access->id = $access->institution; $access->name = institution_display_name($access->institution); } else { $key = $access->accesstype; } } } if ($key) { if (!isset($data[$vi['type']][$vi['id']]['accessgroups'][$key])) { $data[$vi['type']][$vi['id']]['accessgroups'][$key] = (array) $access; } } else { $data[$vi['type']][$vi['id']]['accessgroups'][] = (array) $access; } } return $data; }
* @param int $percent How far complete the export is * @param string $status A human-readable string describing the current step */ function export_iframe_progress_handler($percent, $status) { print_iframe_progress_handler($percent, $status); flush(); } // Bail if we don't have enough data to do an export if (!isset($exportdata['format']) || !isset($exportdata['what']) || !isset($exportdata['views'])) { export_iframe_die(get_string('unabletogenerateexport', 'export')); exit; } safe_require('export', $exportdata['format']); $user = new User(); $user->find_by_id($USER->get('id')); $class = generate_class_name('export', $exportdata['format']); switch ($exportdata['what']) { case 'all': $exporter = new $class($user, PluginExport::EXPORT_ALL_VIEWS, PluginExport::EXPORT_ALL_ARTEFACTS, 'export_iframe_progress_handler'); break; case 'views': $exporter = new $class($user, $exportdata['views'], PluginExport::EXPORT_ARTEFACTS_FOR_VIEWS, 'export_iframe_progress_handler'); break; case 'collections': $exporter = new $class($user, $exportdata['views'], PluginExport::EXPORT_COLLECTIONS, 'export_iframe_progress_handler'); break; default: export_iframe_die(get_string('unabletoexportportfoliousingoptions', 'export')); } $exporter->includefeedback = $exportdata['includefeedback'];
/** * Initialises a theme object based on the theme 'hint' passed. * * If arg is a string, it's taken to be a theme name. If it's a user * object, we ask it for a theme name. If it's an integer, we pretend * that's a user ID and ask for the theme for that user. * * If the theme they want doesn't exist, the object is initialised for the * default theme. This means you can initialise one of these for a user * and then use it without worrying if the theme exists. * * @param mixed $arg Theme name, user object or user ID */ public function __construct($arg) { if (is_string($arg)) { $themename = $arg; } else { if ($arg instanceof User) { $themename = $arg->get('theme'); } else { if (is_int($arg)) { $user = new User(); $user->find_by_id($arg); $themename = $user->get('theme'); } else { throw new SystemException("Argument to Theme::__construct was not a theme name, user object or user ID"); } } } if (!$themename) { // Theme to show to when no theme has been suggested if (!($themename = get_config('theme'))) { $themename = 'raw'; } } $this->init_theme($themename); }