示例#1
0
require_login();
$pagetitle = get_string('keymanager', 'local_rcommon');
$url = new moodle_url('/local/rcommon/formInsert.php', $_REQUEST);
// Base URL
$context = context_system::instance();
$PAGE->set_context($context);
$PAGE->set_heading($pagetitle);
$PAGE->set_url($url);
$PAGE->set_title($pagetitle);
$PAGE->navbar->add($pagetitle, null, null, navigation_node::TYPE_CUSTOM, null);
echo $OUTPUT->header();
$isbn = required_param('isbn', PARAM_TEXT);
$url = base64_decode(optional_param('url', '', PARAM_TEXT));
$key = optional_param('key', false, PARAM_TEXT);
if (!empty($key)) {
    credentials::add($isbn, $key, $USER->id);
    echo '<script>document.location.href="' . $url . '";</script>';
} else {
    echo $OUTPUT->heading(get_string('insertkeymsg', 'local_rcommon'));
    ?>
    <form id="keyform" method="POST">
        <input type="text" name="key">
        <input type="hidden" name="isbn" value="<?php 
    echo $isbn;
    ?>
">
        <input type="hidden" name="url" value="<?php 
    echo base64_encode($url);
    ?>
">
        <input type="submit" value="<?php 
    $ids = implode(',', $ids);
} else {
    $ids = '';
}
$course = $DB->get_record('course', array('id' => $courseid));
//set some text vars
$strsearch = get_string('search');
$strsearchresults = get_string('searchresults');
$strshowall = trim(get_string('showall', 'moodle', ""));
//if isset form doactions
if ($frm = data_submitted()) {
    if (!empty($frm->addselect) && confirm_sesskey()) {
        credentials::bulk_assign_users($book->isbn, $array_ids, $frm->addselect);
    } else {
        if (!empty($frm->removeselect) && confirm_sesskey()) {
            credentials::bulk_unassign_users($book->isbn, $frm->removeselect);
        } else {
            if ($showall) {
                $searchtext = '';
                $courseid = 0;
            }
        }
    }
}
$already_asigned_users = $DB->get_records_sql("SELECT c.euserid as id, u.firstname, u.lastname, u.email FROM {user} u RIGHT JOIN {rcommon_user_credentials} c ON u.id = c.euserid WHERE c.id IN ({$ids}) AND euserid <> 0");
$already_asigned_users_cnt = $already_asigned_users ? count($already_asigned_users) : 0;
//echo '<hr>alredy_asigned_users: ' . serialize($already_asigned_users) . '<hr>';
$already_unassigned = $ids_cnt - $already_asigned_users_cnt;
$search_where = !empty($searchtext) ? " AND (firstname LIKE '%{$searchtext}%' OR lastname LIKE '%{$searchtext}%' OR username LIKE '%{$searchtext}%')" : '';
if (empty($courseid)) {
    // MARSUPIAL ************* MODIFICAT -> Add extra control for just show the users confirmed and non deleted in the assigment books credentials process
    } else {
        $referer = $CFG->wwwroot . '/local/rcommon/users.php';
    }
} else {
    $referer = $CFG->wwwroot . '/local/rcommon/books.php?id=' . $book->id;
}
$form = new local_rcommon_edit_credentials_form();
if ($form->is_cancelled()) {
    redirect($referer);
} else {
    if ($fromform = $form->get_data() and confirm_sesskey()) {
        if (empty($fromform->id)) {
            $userid = $fromform->euserid ? $fromform->euserid : 0;
            $id = credentials::add($fromform->isbn, $fromform->credentials, $userid);
            if (!$id) {
                redirect($referer, get_string('saveko', 'local_rcommon'), 5);
            }
        } else {
            $success = credentials::update($fromform->id, $fromform->isbn, $fromform->credentials);
            if (!$success) {
                redirect($referer, get_string('saveko', 'local_rcommon'), 5);
            }
        }
        redirect($referer, get_string('saveok', 'local_rcommon'), 2);
    } else {
        $credential->backto = $backto;
        $form->set_data($credential);
        $form->display();
    }
}
echo $OUTPUT->footer();
示例#4
0
<?php

session_start();
set_time_limit(0);
require 'classes.php';
$pass = new credentials();
if (isset($_POST['password']) && $pass->checkPassword($_POST['password'])) {
    $_SESSION['loggedin'] = true;
}
$error = "";
if (isset($_POST['password']) && !$pass->checkPassword($_POST['password'])) {
    $error = "Incorrect password.<BR>";
}
if (!isset($_SESSION['loggedin'])) {
    echo <<<EOD
<!DOCTYPE html>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<script src="main.js"></script>
<link href="main.css" rel="stylesheet">
</head>
<body>
<div id="container">

<form action="" method="POST">
<h1>Please log in</h1>
<span style="color:red">{$error}</span>
<input type="password" name="password">
示例#5
0
        $upt->track('status', get_string('keymanager_import_error_21', 'local_rcommon'), 'warning');
        $warning = true;
    } else {
        $processed_credential[$credential->isbn][$credential->credential] = true;
    }
    if ($error) {
        $errors++;
        continue;
    } else {
        if ($warning) {
            $warnings++;
        }
    }
    // Ok Do it
    if ($continue) {
        if (credentials::add($credential->isbn, $credential->credential, $credential->euserid)) {
            $upt->track('status', get_string('success'), 'info');
            $do_ok++;
        } else {
            $upt->track('status', get_string('error'), 'error');
            $do_errors++;
        }
    }
}
$upt->close();
// close table
$cir->close();
// Show the summary
if ($linenum <= 1) {
    // Empty file
    echo $OUTPUT->notification(get_string('keymanager_import_error_17', 'local_rcommon'));
/**
 * Web Service to authenticate users credentials
 * @param object $data -> mod values
 * @return obj -> web service response
 */
function AuthenticateUserContent($data, $usr_creden = false, $showurl = true)
{
    global $CFG, $DB, $USER, $OUTPUT;
    $from = optional_param('from', '', PARAM_TEXT);
    if (!isset($data->bookid) || ($book = $DB->get_record('rcommon_books', array('id' => $data->bookid))) == false) {
        print_error(get_string('nobookid', 'local_rcommon'));
        //save error on bd
    } elseif (($publisher = $DB->get_record('rcommon_publisher', array('id' => $book->publisherid))) == false) {
        print_error(get_string('nopublisher', 'local_rcommon'));
        //save error on bd
    }
    if (!$usr_creden) {
        $usr_creden = credentials::get_by_user_isbn($USER->id, $book->isbn);
    }
    if (!$usr_creden) {
        // Moved $url variable to use it also in the else clause and changed the default behavior
        /*set url*/
        if (isset($_SERVER)) {
            $SERVER_NAME = $_SERVER['SERVER_NAME'];
            $SERVER_PORT = $_SERVER['SERVER_PORT'];
            $SCRIPT_NAME = $_SERVER['REQUEST_URI'];
            $HTTPS = isset($_SERVER['HTTPS']) ? $_SERVER['HTTPS'] : (isset($HTTP_SERVER_VARS['HTTPS']) ? $HTTP_SERVER_VARS['HTTPS'] : 'off');
        } elseif (isset($HTTP_SERVER_VARS)) {
            $SERVER_NAME = $HTTP_SERVER_VARS['SERVER_NAME'];
            $SERVER_PORT = $HTTP_SERVER_VARS['SERVER_PORT'];
            $SCRIPT_NAME = $HTTP_SERVER_VARS['REQUEST_URI'];
            $HTTPS = isset($HTTP_SERVER_VARS['HTTPS']) ? $HTTP_SERVER_VARS['HTTPS'] : 'off';
        }
        if ($SERVER_PORT == 80) {
            $SERVER_PORT = '';
        } else {
            $SERVER_PORT = ':' . $SERVER_PORT;
        }
        if ($HTTPS == '1' || $HTTPS == 'on') {
            $SCHEME = 'https';
        } else {
            $SCHEME = 'http';
        }
        $url = "{$SCHEME}://{$SERVER_NAME}{$SERVER_PORT}{$SCRIPT_NAME}";
        redirect($CFG->wwwroot . '/local/rcommon/formInsert.php?url=' . base64_encode($url) . '&isbn=' . $book->isbn);
        exit;
        //save error on bd
    } else {
        if (!empty($data->unitid) && ($unit = $DB->get_record('rcommon_books_units', array('id' => $data->unitid))) == false) {
            print_error(get_string('nounit', 'block_rcommon'));
            //save error on bd
        } else {
            if (!empty($data->activityid) && ($activ = $DB->get_record('rcommon_books_activities', array('id' => $data->activityid))) == false) {
                print_error('noactivity', 'block_rcommon');
                //save error on bd
            }
        }
    }
    //look for the group if he has anyone assigned
    $grupo = $DB->get_recordset_sql("SELECT GRUPO.id\r\n                        FROM {user} USERS\r\n                        JOIN {role_assignments} ra ON ra.userid = USERS.id\r\n                        JOIN {role} r ON ra.roleid = r.id\r\n                        JOIN {context} con ON ra.contextid = con.id\r\n                        JOIN {course} COURSE ON COURSE.id = con.instanceid\r\n                        AND con.contextlevel =50\r\n                        JOIN {groups} GRUPO ON GRUPO.courseid = COURSE.id\r\n                        JOIN {groups_members} MEMBER ON MEMBER.groupid = GRUPO.id\r\n                        AND MEMBER.userid = USERS.id\r\n                        WHERE COURSE.id = {$data->course}\r\n                        AND USERS.id = {$USER->id}");
    foreach ($grupo as $grp) {
        $grupoid = $grp->id;
    }
    try {
        $client = get_marsupial_ws_client($publisher, true);
        $params = new stdClass();
        $params->Credencial = new SoapVar($usr_creden->credentials, XSD_STRING, "string", "http://www.w3.org/2001/XMLSchema");
        $params->ISBN = new SoapVar($book->isbn, XSD_STRING, "string", "http://www.w3.org/2001/XMLSchema");
        $params->IdUsuario = new SoapVar($usr_creden->euserid, XSD_STRING, "string", "http://www.w3.org/2001/XMLSchema");
        //$params->NombreApe = new SoapVar($USER->firstname." ".$USER->lastname, XSD_STRING, "string", "http://www.w3.org/2001/XMLSchema");
        //convert rcommon_teacherroles to array
        $rcommon_teacherroles = explode(',', get_config('rcommon', 'teacherroles'));
        //get user role
        // To avoid problems because in some cases the courseid was null
        $context = context_course::instance($data->course);
        $iduserrole = array();
        if ($roles = get_user_roles($context, $USER->id)) {
            foreach ($roles as $role) {
                $iduserrole = $role->roleid;
            }
        }
        //set role string
        $rolestring = "ESTUDIANTE";
        if (in_array($iduserrole, $rcommon_teacherroles)) {
            $rolestring = "PROFESOR";
        }
        //check if the web service is prepared to receive rol parameter
        $parsed_wsdl = rcommon_get_wsdl($publisher->urlwsauthentication . '?wsdl');
        if (core_text::strpos($parsed_wsdl, 'name="Rol"') && $rolestring == "PROFESOR") {
            $params->Rol = new SoapVar($rolestring, XSD_STRING, "string", "http://www.w3.org/2001/XMLSchema");
        }
        $params->IdCurso = new SoapVar($data->course, XSD_STRING, "string", "http://www.w3.org/2001/XMLSchema");
        $centerid = isset($CFG->center) ? $CFG->center : '';
        $params->IdCentro = new SoapVar($centerid, XSD_STRING, "string", "http://www.w3.org/2001/XMLSchema");
        $params->URLResultado = new SoapVar("{$CFG->wwwroot}/mod/rcontent/WebServices/wsSeguimiento.php", XSD_STRING, "string", "http://www.w3.org/2001/XMLSchema");
        $params->IdContenidoLMS = new SoapVar($data->id, XSD_STRING, "string", "http://www.w3.org/2001/XMLSchema");
        $unitid = isset($unit->code) ? $unit->code : '';
        $params->IdUnidad = new SoapVar($unitid, XSD_STRING, "string", "http://www.w3.org/2001/XMLSchema");
        $activid = isset($activ->code) ? $activ->code : '';
        $params->IdActividad = new SoapVar($activid, XSD_STRING, "string", "http://www.w3.org/2001/XMLSchema");
        // He has been assigned a group
        if (isset($grupoid)) {
            $params->IdGrupo = new SoapVar($grupoid, XSD_STRING, "string", "http://www.w3.org/2001/XMLSchema");
        }
        $response = $client->__soapCall("AutenticarUsuarioContenido", array($params));
        log_to_file("wsAutenthication request: " . $client->__getLastRequest());
        log_to_file("wsAutenthication response: " . $client->__getLastResponse());
    } catch (Exception $e) {
        log_to_file("wsAutenthication exception: " . get_string('bad_wsdl_connection', 'local_rcommon'));
        echo '<script type="text/javascript">window.alert("' . get_string('bad_wsdl_connection', 'local_rcommon') . '"); history.go(-1);</script>';
        echo $OUTPUT->notification(get_string('bad_wsdl_connection', 'local_rcommon'));
        die;
    }
    //test the response to set parameters name to the standars
    foreach ($response->AutenticarUsuarioContenidoResult as $key => $value) {
        switch (core_text::strtolower($key)) {
            case "descripcion":
                $response->AutenticarUsuarioContenidoResult->Descripcion = $value;
                break;
            case "codigo":
                $response->AutenticarUsuarioContenidoResult->Codigo = $value;
                break;
            case "url":
                $response->AutenticarUsuarioContenidoResult->URL = $value;
                break;
        }
    }
    //check if there are any response error
    if ($response->AutenticarUsuarioContenidoResult->Codigo <= 0) {
        //test if isset the url
        //
        $urlok = false;
        $message = "Instance ID: " . $data->id . ", Text: " . get_string('wsautenticationerror', $data->module == 'check_credentials' ? 'rcontent' : $data->module) . ", Code: " . $response->AutenticarUsuarioContenidoResult->Codigo . ", Detail: " . $response->AutenticarUsuarioContenidoResult->Descripcion;
        if (isset($response->AutenticarUsuarioContenidoResult->URL)) {
            $urlok = test_ws_url($response->AutenticarUsuarioContenidoResult->URL);
        }
        if ($urlok) {
            $message .= ", URL: " . $urlok;
        }
        rcommon_ws_error('AuthenticateUserContent', $message, $data->module, $data->cmid, $data->course);
        if ($urlok && $showurl) {
            $msg = '<br><br>' . @get_string('urlmoreinfo', 'local_rcommon', $urlok);
        } else {
            $msg = "";
        }
        //set the description to show
        $desctext = get_string('error_code_' . $response->AutenticarUsuarioContenidoResult->Codigo, 'local_rcommon');
        if (core_text::substr($desctext, 0, 2) == '[[') {
            $desctext = $response->AutenticarUsuarioContenidoResult->Codigo;
        }
        if (isset($response->AutenticarUsuarioContenidoResult->Descripcion) && !empty($response->AutenticarUsuarioContenidoResult->Descripcion)) {
            $desctext .= '<br>' . $response->AutenticarUsuarioContenidoResult->Descripcion;
        }
        print_error(get_string('error_authentication', 'local_rcommon', $response->AutenticarUsuarioContenidoResult->Codigo) . '<br>' . $desctext . $msg);
    } else {
        return $response;
    }
}
示例#7
0
             $jsmodule = array('name' => 'local_rcommon', 'fullpath' => '/local/rcommon/javascript.js', 'requires' => array('base', 'io', 'panel'));
             $PAGE->requires->js_init_call('M.local_rcommon.init', array(), true, $jsmodule);
         }
     }
     break;
 case 'delete':
     $id = required_param('id', PARAM_INT);
     $username = isset($username) ? $username : optional_param('username', $USER->username, PARAM_TEXT);
     $confirm = optional_param('confirm', false, PARAM_BOOL);
     if (!$confirm) {
         echo '<p>' . get_string('keyconfirmdelete', 'local_rcommon') . '</p>';
         echo '<br/>';
         echo '<a href="users.php?action=delete&username='******'&confirm=true&id=' . $id . '">' . get_string('keydelbtn', 'local_rcommon') . '</a> &nbsp;&nbsp;<a href="users.php?action=manage&username='******'">' . get_string('back') . '</a>';
     } else {
         // Delete
         credentials::delete($id);
         echo '<script>document.location.href="users.php?action=manage&username='******'";</script>';
     }
     break;
 default:
     require_capability('local/rcommon:managecredentials', context_system::instance());
     $usercount = get_users(false, '', true);
     $with_credentials = $DB->get_field_sql('SELECT DISTINCT count(u.id) AS with_credentials FROM {user} u WHERE u.id IN (SELECT uc.euserid FROM {rcommon_user_credentials} uc GROUP BY uc.euserid)');
     $a = new StdClass();
     $a->total_users = $usercount;
     $a->with_credentials = $with_credentials;
     echo '<p>' . get_string('users_proportion', 'local_rcommon', $a) . '</p>';
     $context = context_system::instance();
     $site = get_site();
     $sort = optional_param('sort', 'firstname', PARAM_TEXT);
     $dir = optional_param('dir', 'ASC', PARAM_TEXT);
    $PAGE->set_pagelayout('incourse');
} else {
    admin_externalpage_setup('marsupial_credentials_users');
    $username = required_param('username', PARAM_TEXT);
    $pagetitle = get_string('keyaddingforuser', 'local_rcommon', $username);
}
$params = array();
$params['username'] = $username;
$form = new local_rcommon_add_credentials_form();
if ($form->is_cancelled()) {
    $referer = $CFG->wwwroot . '/local/rcommon/users.php?action=manage&username='******'/local/rcommon/users.php?action=manage&username='******'saveko', 'local_rcommon'), 5);
        }
        redirect($referer, get_string('saveok', 'local_rcommon'), 2);
    } else {
        echo $OUTPUT->header();
        echo $OUTPUT->heading($pagetitle);
        $credential = new StdClass();
        $credential->username = $username;
        $form->set_data($credential);
        $form->display();
        echo $OUTPUT->footer();
    }
}
示例#9
0
 function __construct()
 {
     $actions = array("sendToWhse", "oversold", "complete");
     parent::__construct();
     if (isset($_POST['action']) && in_array($_POST['action'], $actions)) {
         if ($_POST['action'] === "sendToWhse") {
             $this->updateStatus(1);
             $mail = new email();
             $mail->pulled($_POST);
             $trak = new trakItem();
             $trak->returnItem($_POST['trakSKU'], $_POST['qty']);
             $this->log("ITEM SENT TO WHSE: " . $_POST['orderID'] . " " . $_POST['scSKU']);
         }
         if ($_POST['action'] === "oversold") {
             $this->updateStatus(2);
             $mail = new email();
             $mail->oversold($_POST);
             $sc = new SCitem($_POST['scSKU']);
             $sc->setQty(0);
             $this->log("ITEM MARKED OVERSOLD: " . $_POST['orderID'] . " " . $_POST['scSKU']);
         }
         if ($_POST['action'] === "complete") {
             $this->completeItem($_POST);
             $this->log("ITEM REMOVED AS COMPLETE: " . $_POST['orderID'] . " " . $_POST['scSKU']);
         }
     }
 }