Exemplo n.º 1
0
 function get_user()
 {
     if (is_null($this->logged_in_user)) {
         $id = $this->session->userdata('flogged_in_id');
         if (is_numeric($id)) {
             $u = new user();
             $u->get_by_id($id);
             if ($u->exists()) {
                 $this->logged_in_user = $u;
                 return $this->logged_in_user;
             }
         }
         return FALSE;
     } else {
         return $this->logged_in_user;
     }
 }
Exemplo n.º 2
0
 /**
  * Add new maintainer
  *
  * @static
  * @param  mixed  Name of the package or it's ID
  * @param  string Handle of the user
  * @param  string Role of the user
  * @param  integer Is the developer actively working on the project?
  * @return mixed True or PEAR error object
  */
 static function add($package, $user, $role, $active = 1)
 {
     global $dbh;
     include_once 'pear-database-user.php';
     if (!user::exists($user)) {
         throw new InvalidArgumentException("User {$user} does not exist");
     }
     include_once 'pear-database-package.php';
     if (is_string($package)) {
         $package = package::info($package, 'id');
     }
     $sql = 'INSERT INTO maintains (handle, package, role, active) VALUES (?, ?, ?, ?)';
     $err = $dbh->query($sql, array($user, $package, $role, (int) $active));
     if (DB::isError($err)) {
         return $err;
     }
     $packagename = package::info($package, 'name');
     include_once 'pear-rest.php';
     $pear_rest = new pearweb_Channel_REST_Generator(PEAR_REST_PATH, $dbh);
     $pear_rest->savePackageMaintainerREST($packagename);
     return true;
 }
Exemplo n.º 3
0
 if (PEAR::isError($pacid)) {
     $errors[] = $pacid->getMessage();
     break;
 }
 include_once 'pear-database-user.php';
 if (!auth_check('pear.admin') && !auth_check('pear.qa') && !user::maintains($auth_user->handle, $pacid, 'lead')) {
     $errors[] = 'You don\'t have permissions to upload this release.';
     break;
 }
 $license = $info->getLicense();
 if (is_array($license)) {
     $license = $license['_content'];
 }
 $users = array();
 foreach ($info->getMaintainers() as $user) {
     if (!user::exists($user['handle'])) {
         $errors[] = 'Unknown user: '******'handle'];
         continue;
     }
     $users[strtolower($user['handle'])] = array('role' => $user['role'], 'active' => !isset($user['active']) || $user['active'] == 'yes');
 }
 include_once 'pear-database-maintainer.php';
 $e = maintainer::updateAll($pacid, $users, false, true);
 if (PEAR::isError($e)) {
     $errors[] = $e->getMessage();
     break;
 }
 $e = package::updateInfo($pacid, array('summary' => $info->getSummary(), 'description' => $info->getDescription(), 'license' => $license));
 if (PEAR::isError($e)) {
     $errors[] = $e->getMessage();
     break;
Exemplo n.º 4
0
<?php

$ci =& get_instance();
$u = new user();
$u->get_by_name($ci->input->post('name'));
if ($u->exists()) {
    $ci->app->add_error("user name duplication please choose another name ");
} else {
    $u->name = $ci->input->post('name');
    $u->set_password($ci->input->post('password'));
    $u->email = $ci->input->post('email');
    $u->level = $ci->input->post('level');
    $u->save();
    redirect($ci->app->app_url('View users'));
}
Exemplo n.º 5
0
 function validateRequest($handle, $password, $password2, $name)
 {
     $errors = array();
     if (empty($handle) || !preg_match('/^[0-9a-z_]{2,20}\\z/', $handle)) {
         $errors[] = 'Username is invalid.';
         $display_form = true;
     }
     if ($password == md5('') || empty($password)) {
         $errors[] = 'Password must not be empty';
     }
     if ($password !== $password2) {
         $errors[] = 'Passwords do not match';
     }
     include_once 'pear-database-user.php';
     if (user::exists($handle)) {
         $errors[] = 'User name "' . $handle . '" already exists, please choose another user name';
     }
     $name_parts = explode(' ', $name, 2);
     if (count($name_parts) == 2) {
         $firstname = $name_parts[0];
         $lastname = $name_parts[1];
     } else {
         $firstname = $name_parts[0];
         $lastname = null;
     }
     // First- and lastname must be longer than 1 character
     if (strlen($firstname) == 1) {
         $errors[] = 'Your firstname appears to be too short.';
     }
     if (strlen($lastname) == 1) {
         $errors[] = 'Your lastname appears to be too short.';
     }
     // No names with only uppercase letters
     if ($firstname === strtoupper($firstname)) {
         $errors[] = 'Your firstname must not consist of only uppercase letters.';
     }
     if ($lastname === strtoupper($lastname)) {
         $errors[] = 'Your lastname must not consist of only uppercase letters.';
     }
     return $errors;
 }
Exemplo n.º 6
0
     include_once 'pear-database-release.php';
     $items = release::getPopular(10, true);
     foreach ($items as $i => $item) {
         $items[$i]['releasenotes'] = 'Downloads per day: ' . number_format($item['releasenotes'], 2);
     }
     $channel_title = 'PEAR: Popular releases';
     $channel_description = 'The most popular releases in PEAR.';
     break;
 case 'bug':
     $_REQUEST = array('id' => $argument, 'format' => 'rss');
     include dirname(dirname(__FILE__)) . '/bugs/rss/bug.php';
     exit;
 case 'user':
     $user = $argument;
     include_once 'pear-database-user.php';
     if (!user::exists($user)) {
         rss_bailout();
     }
     $name = user::info($user, "name");
     $channel_title = "PEAR: Latest releases for " . $user;
     $channel_description = "The latest releases for the PEAR developer " . $user . " (" . $name['name'] . ")";
     $items = user::getRecentReleases($user);
     break;
 case 'pkg':
     $package = $argument;
     include_once 'pear-database-package.php';
     if (package::isValid($package) == false) {
         rss_bailout();
         return PEAR::raiseError("The requested URL " . $_SERVER['REQUEST_URI'] . " was not found on this server.");
     }
     $channel_title = "Latest releases of " . $package;
function perform_user_removal()
{
    // User accounts are not actually deleted from the database.  They are flagged as INACTIVE because the user ID is referenced
    // by other tables that need to maintain a historical record of actions performed by that user (e.g. rappels.confirmed_by).
    if (!isset($_POST['user_id'])) {
        throw new Exception('You must specify a user account to remove!');
    }
    if (!user::exists($_POST['user_id'])) {
        throw new Exception('The requested user account does not exist!');
    }
    $user = new user();
    $user->load($_POST['user_id']);
    $user->set('inactive', 1);
    $user->save();
    return 1;
}
Exemplo n.º 8
0
     case update:
         group::set($_GET[user], $_GET[group]);
         break;
     case add:
         if ($_GET[user] and $_GET[password]) {
             if (!user::exists($_GET[user])) {
                 $user = $_GET[user];
                 $md5Password = md5($_GET[password]);
                 database::query("INSERT INTO user SET user='******',password='******',`group`='4'");
             } else {
                 echo "<div id='alert'><b>User schon vergeben</div>";
             }
         }
         break;
     case deleteuser:
         if (user::exists($id)) {
             echoalert("Benutzer " . user::name($id) . " gelöscht");
             database::query("DELETE FROM user WHERE ID='{$id}'");
         }
         break;
 }
 $userArray = fetch_to_array(database::query("SELECT user.ID,user.user,user.password,user.group,user.status,`group`.name FROM user,`group` WHERE user.group=group.ID ORDER BY user"), "");
 // list users
 echo "<div id='infobig'>";
 echo "<fieldset><legend>User</legend>";
 echo "<table border='1'>";
 echo "<th>User</th>";
 echo "<th>Group</th>";
 echo "<th></th>";
 echo "<th></th>";
 echo "<th>Last Login</th>";
Exemplo n.º 9
0
<?php

$ci =& get_instance();
$l = new user();
$l->get_by_id($ci->uri->segment(5));
if (!$l->exists()) {
    $ci->app->add_error("User not found");
} else {
    $l->delete();
    $ci->app->add_info(" user deleted ");
}
Exemplo n.º 10
0
   +----------------------------------------------------------------------+
   $Id$
*/
/**
 * On 404 error this will search for a package with the same
 * name as the requested document. Thus enabling urls such as:
 *
 * http://pear.php.net/Mail_Mime
 */
/**
 * Requesting something like /~foobar will redirect to the account
 * information page of the user "foobar".
 */
if (strlen($_SERVER['REDIRECT_URL']) > 0 && $_SERVER['REDIRECT_URL'][1] == '~') {
    $user = substr($_SERVER['REDIRECT_URL'], 2);
    if (preg_match(PEAR_COMMON_USER_NAME_REGEX, $user) && user::exists($user)) {
        localRedirect("/user/" . urlencode($user));
    }
}
$pkg = strtr($_SERVER['REDIRECT_URL'], '-', '_');
$pinfo_url = '/package/';
// Check strictly
$name = package::info(basename($pkg), 'name');
if (!DB::isError($name) && !empty($name)) {
    if (!empty($name)) {
        localRedirect($pinfo_url . $name);
    } else {
        $name = package::info(basename($pkg), 'name', true);
        if (!empty($name)) {
            header('HTTP/1.0 301 Moved Permanently');
            header('Location: http://pear.php.net/package/' . $name);
Exemplo n.º 11
0
 private function _fget_user()
 {
     $id = $this->session->userdata('flogged_in_id');
     if (is_numeric($id)) {
         $u = new user();
         $u->get_by_id($id);
         if ($u->exists()) {
             $logged_in_user = $u;
             return $logged_in_user;
         }
     }
     return FALSE;
 }
Exemplo n.º 12
0
    // $Lname=input::get('LastName');
    // echo $Fname." ".$Lname ;
    /*
     * if ($user->hasPermission ( 'admin' )) {
     * echo 'You are an admin';
     * }
     */
    // $currentID=$_SESSION['UserID'];
    // echo $currentID;
    $UserID2 = input::get('User');
    // $user= new user($UserID);
    if (!$UserID2 == input::get('User')) {
        redirect::to('index.php');
    } else {
        $user2 = new user($UserID2);
        if (!$user2->exists()) {
            redirect::to('404');
        } else {
            $data = $user2->data();
            ?>
<link href="<?php 
            echo 'style.css';
            ?>
" rel='stylesheet' type='text/css'>

<h3><?php 
            echo escape($data->UserID);
            ?>
</h3>
<p>FirstName: <?php 
            echo escape($data->FirstName);
Exemplo n.º 13
0
<?php

require_once '../Core/init.php';
if (!($username = input::get('user'))) {
    redirect::to('../index.php');
} else {
    $user = new user($username, $_log);
    if (!$user->exists()) {
        redirect::to(404);
    } else {
        $data = $user->data();
    }
    ?>
	
		<h3><?php 
    echo escape($data->User_Name);
    ?>
</h3>
		<p>Full name: <?php 
    echo escape($data->Name);
    ?>
</p>
	<?php 
}
Exemplo n.º 14
0
 function ___onTarget()
 {
     if ($_REQUEST['action'] == 'register') {
         $GLOBALS['core']->event('register');
         //validation
         if (empty($_REQUEST['username'])) {
             $GLOBALS['err']->add("Name can't be blank.", array('username', 'register'));
         }
         if (user::exists($_REQUEST['username'])) {
             $GLOBALS['err']->add("Name already exists. choose another.", array('username', 'register'));
         }
         if (empty($_REQUEST['password1'])) {
             $GLOBALS['err']->add("Password can't be blank.", array('password1', 'register'));
         } elseif ($_REQUEST['password1'] != $_REQUEST['password2']) {
             $GLOBALS['err']->add("Passwords don't match.", array('password2', 'register'));
         } elseif ($_REQUEST['password1'] == $_REQUEST['password2'] && $GLOBALS['err']->none()) {
             //logout first, just in case
             if (user::whoAmI() == 'temp') {
                 user::logout();
             }
             if (user::register($_REQUEST['username'], $_REQUEST['password1'])) {
                 session_regenerate_id();
                 //sort of prevent session-hijacking
                 $_REQUEST['password'] = $_REQUEST['password1'];
                 $_REQUEST['action'] = 'login';
                 $GLOBALS['state'] = 'successful registration';
                 $GLOBALS['core']->event('registrationSuccess');
             } else {
                 $GLOBALS['err']->add("Unable to register for some reason. Please let us know about it.", 'registration');
                 $GLOBALS['core']->event('registrationFailure');
             }
         }
     }
     if ($_REQUEST['action'] == 'login') {
         $GLOBALS['core']->event('login');
         if (empty($_REQUEST['username'])) {
             $GLOBALS['err']->add("You left out the name.", array('username', 'login'));
         }
         if (empty($_REQUEST['password'])) {
             $GLOBALS['err']->add("You left out the password.", array('password', 'login'));
         }
         if (!empty($_REQUEST['username']) && !empty($_REQUEST['password'])) {
             if (!user::login($_REQUEST['username'], $_REQUEST['password'])) {
                 $GLOBALS['err']->add("Wrong.", 'login');
             } else {
                 $loginSuccess = true;
                 session_regenerate_id();
                 //prevent session hijacking.
             }
         }
         $GLOBALS['core']->event($loginSuccess ? 'loginSuccess' : 'loginFailure');
     }
     if ($_REQUEST['action'] == 'logout') {
         $GLOBALS['core']->event('logout');
         session_regenerate_id(true);
         //kill old session.
         user::logout();
         header("Location: /");
         exit;
     }
     if (!user::loggedIn()) {
         //login as temp user
         //user::loginTemp();
     }
 }
Exemplo n.º 15
0
if (!(isset($maintainers[$auth_user->handle]) && $maintainers[$auth_user->handle]['role'] == 'lead')) {
    auth_require('pear.qa');
}
if (isset($_POST) && isset($_POST['role'])) {
    if (!validate_csrf_token($csrf_token_name)) {
        report_error('Invalid token.');
        response_footer();
        exit;
    }
    // Got a new maintainer?
    if (isset($_POST['handle']['new']) && !empty($_POST['handle']['new'])) {
        $new = strip_tags($_POST['handle']['new']);
        include_once 'pear-database-user.php';
        if (!ereg('^[0-9a-z_]{2,20}$', $new)) {
            report_error('Invalid handle: ' . $new);
        } elseif (!user::exists($new)) {
            report_error($new . ' does not exist.');
        } else {
            $role = $_POST['role']['new'];
            if (!maintainer::isValidRole($role)) {
                report_error('Invalid role.');
            } else {
                if (maintainer::add($pid, $new, $role)) {
                    $message = 'Maintainer ' . $new . 'sucessfully added.';
                    $maintainers[$new] = array('role' => $role, 'active' => 1);
                }
            }
        }
    } else {
        $new = '';
    }
Exemplo n.º 16
0
 /**
  * Add new maintainer
  *
  * @static
  * @param  mixed  Name of the package or it's ID
  * @param  string Handle of the user
  * @param  string Role of the user
  * @param  integer Is the developer actively working on the project?
  * @return mixed True or PEAR error object
  */
 function add($package, $user, $role, $active = 1)
 {
     global $dbh, $pear_rest;
     if (!user::exists($user)) {
         return PEAR::raiseError("User {$user} does not exist");
     }
     if (is_string($package)) {
         $package = package::info($package, 'id');
     }
     $err = $dbh->query("INSERT INTO maintains (handle, package, role, active) VALUES (?, ?, ?, ?)", array($user, $package, $role, (int) $active));
     if (DB::isError($err)) {
         return $err;
     }
     $packagename = package::info($package, 'name');
     $pear_rest->savePackageMaintainerREST($packagename);
     return true;
 }
Exemplo n.º 17
0
/**
 * Process all the students in this class
 *
 * Class properties required:
 *   id               - id of class
 *   criteriatype     - what mark to look at, 0 for final mark, anything else is an element id
 *   engineid         - id of results engine entry
 *   scheduleddate    - date when it was supposed to run
 *   rundate          - date when it is being run
 *
 * Class properties required by sub-functions:
 *   eventtriggertype - what type of trigger the engine uses
 *   lockedgrade     - whether the grade must be locked if "set grade" trigger is used
 *
 * @param $class object The class object see above for required attributes
 * @return boolean Success/failure
 * @uses $CFG
 */
function results_engine_process($class)
{
    global $CFG, $DB;
    $params = array('classid' => $class->id);
    $students = results_engine_get_students($class);
    if (sizeof($students) == 0) {
        return true;
    }
    $params = array('resultsid' => $class->engineid);
    $fields = 'id, actiontype, minimum, maximum, trackid, classid, fieldid, fielddata';
    $actions = $DB->get_records('local_elisprogram_res_action', $params, '', $fields);
    $fieldids = array();
    $classids = array();
    $trackids = array();
    foreach ($actions as $action) {
        if ($action->actiontype == RESULTS_ENGINE_UPDATE_PROFILE) {
            $fieldids[$action->fieldid] = $action->fieldid;
        } else {
            if ($action->actiontype == RESULTS_ENGINE_ASSIGN_CLASS) {
                $classids[$action->classid] = $action->classid;
            } else {
                if ($action->actiontype == RESULTS_ENGINE_ASSIGN_TRACK) {
                    $trackids[$action->trackid] = $action->trackid;
                }
            }
        }
    }
    foreach ($fieldids as $id) {
        if ($record = $DB->get_record('local_eliscore_field', array('id' => $id))) {
            $userfields[$id] = new field($record, null, array(), true);
        }
    }
    $classes = $DB->get_records_list('local_elisprogram_cls', 'id', $classids);
    $tracks = $DB->get_records_list('local_elisprogram_trk', 'id', $trackids);
    // Log that the class has been processed
    $log = new stdClass();
    $log->classid = $class->id;
    $log->datescheduled = $class->scheduleddate;
    $log->daterun = $class->rundate;
    $classlogid = $DB->insert_record('local_elisprogram_res_clslog', $log);
    $log = new stdClass();
    $log->classlogid = $classlogid;
    $log->daterun = $class->rundate;
    // Find the correct action to take based on student marks
    foreach ($students as $student) {
        $do = null;
        foreach ($actions as $action) {
            if (elis_float_comp($student->grade, $action->minimum, '>=') && elis_float_comp($student->grade, $action->maximum, '<=')) {
                $do = $action;
                break;
            }
        }
        if ($do != null) {
            $obj = new object();
            switch ($do->actiontype) {
                case RESULTS_ENGINE_ASSIGN_TRACK:
                    usertrack::enrol($student->userid, $do->trackid);
                    $message = 'results_action_assign_track';
                    $track = $tracks[$do->trackid];
                    $obj->name = $track->name . ' (' . $track->idnumber . ')';
                    break;
                case RESULTS_ENGINE_ASSIGN_CLASS:
                    $enrol = new student();
                    $enrol->classid = $do->classid;
                    $enrol->userid = $student->userid;
                    $enrol->save();
                    $message = 'results_action_assign_class';
                    $obj->name = $classes[$do->classid]->idnumber;
                    break;
                case RESULTS_ENGINE_UPDATE_PROFILE:
                    if (!array_key_exists($do->fieldid, $userfields)) {
                        print get_string('results_field_not_found', RESULTS_ENGINE_LANG_FILE, $do) . "\n";
                        break;
                    }
                    /*
                    $context = \local_elisprogram\context\user::instance($student->userid);
                    field_data::set_for_context_and_field($context, $userfields[$do->fieldid], $do->fielddata);
                    */
                    //set field
                    $filter = new select_filter('id = :userid', array('userid' => $student->userid));
                    if (user::exists($filter)) {
                        //get user
                        $user = user::find($filter);
                        $user = $user->current();
                        //set field
                        $field = 'field_' . $userfields[$do->fieldid]->shortname;
                        $user->{$field} = $do->fielddata;
                        $user->save();
                    }
                    $message = 'results_action_update_profile';
                    $obj->name = $userfields[$do->fieldid]->shortname;
                    $obj->value = $do->fielddata;
                    break;
                default:
                    // If we don't know what we're doing, do nothing.
                    break;
            }
            $obj->id = $do->id;
            $log->action = get_string($message, RESULTS_ENGINE_LANG_FILE, $obj);
            $log->userid = $student->userid;
            $DB->insert_record('local_elisprogram_res_stulog', $log, false);
        }
    }
    if (isset($class->cron) && $class->cron) {
        print get_string('results_class_processed', RESULTS_ENGINE_LANG_FILE, $class) . "\n";
    }
    return true;
}