예제 #1
0
파일: lib.php 프로젝트: Br3nda/mahara
 public function dump_export_data()
 {
     if ($this->exporter->get('viewexportmode') == PluginExport::EXPORT_LIST_OF_VIEWS && $this->exporter->get('artefactexportmode') == PluginExport::EXPORT_ARTEFACTS_FOR_VIEWS) {
         // Dont' care about resume in this case
         return;
     }
     $smarty = $this->exporter->get_smarty('../../', 'resume');
     $smarty->assign('page_heading', get_string('resumeofuser', 'artefact.resume', full_name($this->exporter->get('user'))));
     $smarty->assign('breadcrumbs', array(array('text' => get_string('resume', 'artefact.resume'), 'path' => 'index.html')));
     if ($artefacts = get_column_sql("SELECT id\n            FROM {artefact}\n            WHERE owner = ?\n            AND artefacttype IN\n            (SELECT name FROM {artefact_installed_type} WHERE plugin = 'resume')", array($this->exporter->get('user')->get('id')))) {
         foreach ($artefacts as $id) {
             $artefact = artefact_instance_from_id($id);
             $rendered = $artefact->render_self(array());
             $smarty->assign($artefact->get('artefacttype'), $rendered['html']);
         }
     }
     $content = $smarty->fetch('export:html/resume:index.tpl');
     if (false === file_put_contents($this->fileroot . 'index.html', $content)) {
         throw new SystemException("Unable to create index.html for resume");
     }
 }
/**
 * Add the users to the system. Make sure that they have to change their
 * password on next login also.
 */
function uploadcsv_submit(Pieform $form, $values)
{
    global $SESSION, $CSVDATA, $FORMAT;
    $formatkeylookup = array_flip($FORMAT);
    $authinstance = (int) $values['authinstance'];
    $authobj = get_record('auth_instance', 'id', $authinstance);
    $institution = new Institution($authobj->institution);
    $maxusers = $institution->maxuseraccounts;
    if (!empty($maxusers)) {
        $members = count_records_sql('
            SELECT COUNT(*) FROM {usr} u INNER JOIN {usr_institution} i ON u.id = i.usr
            WHERE i.institution = ? AND u.deleted = 0', array($institution->name));
        if ($members + count($CSVDATA) > $maxusers) {
            $SESSION->add_error_msg(get_string('uploadcsvfailedusersexceedmaxallowed', 'admin'));
            redirect('/admin/users/uploadcsv.php');
        }
    }
    log_info('Inserting users from the CSV file');
    db_begin();
    $addedusers = array();
    foreach ($CSVDATA as $record) {
        log_debug('adding user ' . $record[$formatkeylookup['username']]);
        $user = new StdClass();
        $user->authinstance = $authinstance;
        $user->username = $record[$formatkeylookup['username']];
        $user->firstname = $record[$formatkeylookup['firstname']];
        $user->lastname = $record[$formatkeylookup['lastname']];
        $user->password = $record[$formatkeylookup['password']];
        $user->email = $record[$formatkeylookup['email']];
        if (isset($formatkeylookup['studentid'])) {
            $user->studentid = $record[$formatkeylookup['studentid']];
        }
        if (isset($formatkeylookup['preferredname'])) {
            $user->preferredname = $record[$formatkeylookup['preferredname']];
        }
        $user->passwordchange = (int) $values['forcepasswordchange'];
        $profilefields = new StdClass();
        foreach ($FORMAT as $field) {
            if ($field == 'username' || $field == 'password') {
                continue;
            }
            $profilefields->{$field} = $record[$formatkeylookup[$field]];
        }
        $user->id = create_user($user, $profilefields, $institution, $authobj);
        if ($values['emailusers']) {
            $addedusers[] = $user;
        }
    }
    db_commit();
    // Only send e-mail to users after we're sure they have been inserted
    // successfully
    $straccountcreatedtext = $values['forcepasswordchange'] ? 'accountcreatedchangepasswordtext' : 'accountcreatedtext';
    $straccountcreatedhtml = $values['forcepasswordchange'] ? 'accountcreatedchangepasswordhtml' : 'accountcreatedhtml';
    if ($values['emailusers'] && $addedusers) {
        foreach ($addedusers as $user) {
            $failedusers = array();
            try {
                email_user($user, null, get_string('accountcreated', 'mahara', get_config('sitename')), get_string($straccountcreatedtext, 'mahara', $user->firstname, get_config('sitename'), $user->username, $user->password, get_config('wwwroot'), get_config('sitename')), get_string($straccountcreatedhtml, 'mahara', $user->firstname, get_config('wwwroot'), get_config('sitename'), $user->username, $user->password, get_config('wwwroot'), get_config('wwwroot'), get_config('sitename')));
            } catch (EmailException $e) {
                log_info($e->getMessage());
                $failedusers[] = $user;
            }
        }
        if ($failedusers) {
            $message = get_string('uploadcsvsomeuserscouldnotbeemailed', 'admin') . "\n<ul>\n";
            foreach ($failedusers as $user) {
                $message .= '<li>' . full_name($user) . ' &lt;' . hsc($user->email) . "&gt;</li>\n";
            }
            $message .= "</ul>\n";
            $SESSION->add_info_msg($message, false);
        }
    }
    log_info('Inserted ' . count($CSVDATA) . ' records');
    $SESSION->add_ok_msg(get_string('uploadcsvusersaddedsuccessfully', 'admin'));
    redirect('/admin/users/uploadcsv.php');
}
예제 #3
0
 /**
  * create the feed header and author info
  */
 private function export_header()
 {
     $this->smarty->assign('userid', $this->get('user')->get('id'));
     $this->smarty->assign('name', full_name($this->get('user')));
     $this->smarty->assign('email', $this->get('user')->get('email'));
     $this->smarty->assign('export_time', $this->exporttime);
     $this->smarty->assign('export_time_rfc3339', PluginExportLeap::format_rfc3339_date($this->exporttime));
     require get_config('docroot') . 'export/leap/version.php';
     $this->smarty->assign('leap_export_version', $config->version);
     $this->xml .= $this->smarty->fetch('export:leap:header.tpl');
 }
예제 #4
0
/**
 * function to format a users name when there is no user to look at them
 * ie when display_name is not going to work..
 */
function display_default_name($user)
{
    if (is_array($user)) {
        $user = (object) $user;
    } else {
        if (is_numeric($user)) {
            $user = get_record('usr', 'id', $user);
        }
    }
    if (!is_object($user)) {
        throw new InvalidArgumentException("Invalid user passed to display_name");
    }
    if ($user instanceof User) {
        $userObj = $user;
        $user = new StdClass();
        $user->id = $userObj->get('id');
        $user->preferredname = $userObj->get('preferredname');
        $user->firstname = $userObj->get('firstname');
        $user->lastname = $userObj->get('lastname');
        $user->deleted = $userObj->get('deleted');
    }
    return empty($user->preferredname) ? full_name($user) : $user->preferredname;
}
예제 #5
0
function finish_import()
{
    global $SESSION, $ADDEDUSERS, $FAILEDUSERS, $EMAILUSERS;
    $totalusers = count($ADDEDUSERS) + count($FAILEDUSERS);
    log_info('Imported ' . count($ADDEDUSERS) . '/' . $totalusers . ' users successfully');
    if (!empty($ADDEDUSERS)) {
        $SESSION->add_ok_msg(get_string('importednuserssuccessfully', 'admin', count($ADDEDUSERS), $totalusers));
    }
    // Only send e-mail to users after we're sure they have been inserted
    // successfully
    if ($EMAILUSERS && $ADDEDUSERS) {
        foreach ($ADDEDUSERS as $user) {
            $noemailusers = array();
            try {
                email_user($user, null, get_string('accountcreated', 'mahara', get_config('sitename')), get_string('accountcreatedchangepasswordtext', 'mahara', $user->firstname, get_config('sitename'), $user->username, $user->clearpasswd, get_config('wwwroot'), get_config('sitename')), get_string('accountcreatedchangepasswordhtml', 'mahara', $user->firstname, get_config('wwwroot'), get_config('sitename'), $user->username, $user->clearpasswd, get_config('wwwroot'), get_config('wwwroot'), get_config('sitename')));
            } catch (EmailException $e) {
                log_info($e->getMessage());
                $noemailusers[] = $user;
            }
        }
        if ($noemailusers) {
            $message = get_string('uploadcsvsomeuserscouldnotbeemailed', 'admin') . "\n<ul>\n";
            foreach ($noemailusers as $user) {
                $message .= '<li>' . full_name($user) . ' &lt;' . hsc($user->email) . "&gt;</li>\n";
            }
            $message .= "</ul>\n";
            $SESSION->add_info_msg($message, false);
        }
    }
    if (!empty($FAILEDUSERS)) {
        $message = get_string('importfailedfornusers', 'admin', count($FAILEDUSERS), $totalusers) . "\n<ul>\n";
        foreach ($FAILEDUSERS as $username => $error) {
            $message .= '<li>' . hsc($username) . ': ' . hsc($error) . "</li>\n";
        }
        $message .= "</ul>\n";
        $SESSION->add_error_msg($message, false);
    }
    redirect(get_config('wwwroot') . '/admin/users/bulkimport.php');
}
    WHERE u.suspendedcusr IS NOT NULL
    AND u.deleted = 0 ' . $instsql . '
    GROUP BY
        u.id, u.firstname, u.lastname, u.studentid, u.suspendedctime, u.suspendedreason,
        ua.firstname, ua.lastname
    ORDER BY u.suspendedctime, u.id
    LIMIT ?
    OFFSET ?', array($limit, $offset));
if (!$data) {
    $data = array();
} else {
    $institutions = get_records_sql_array('
        SELECT ui.usr, ui.studentid, i.displayname
        FROM {usr_institution} ui INNER JOIN {institution} i ON ui.institution = i.name
        WHERE ui.usr IN (' . join(',', array_keys($data)) . ')', null);
    if ($institutions) {
        foreach ($institutions as &$i) {
            $data[$i->usr]->institutions[] = $i->displayname;
            $data[$i->usr]->institutionids[] = $i->studentid;
        }
    }
    $data = array_values($data);
    foreach ($data as &$record) {
        $record->name = full_name($record);
        $record->firstname = $record->cusrfirstname;
        $record->lastname = $record->cusrlastname;
        $record->cusrname = full_name($record);
        unset($record->firstname, $record->lastname);
    }
}
echo json_encode(array('count' => $count, 'limit' => $limit, 'offset' => $offset, 'data' => $data));
예제 #7
0
/**
 * Add the users to the system. Make sure that they have to change their
 * password on next login also.
 */
function uploadcsv_submit(Pieform $form, $values)
{
    global $USER, $SESSION, $CSVDATA, $FORMAT, $UPDATES;
    $formatkeylookup = array_flip($FORMAT);
    $authinstance = (int) $values['authinstance'];
    $authrecord = get_record('auth_instance', 'id', $authinstance);
    $authobj = AuthFactory::create($authinstance);
    $institution = new Institution($authobj->institution);
    $maxusers = $institution->maxuseraccounts;
    if (!empty($maxusers)) {
        $members = count_records_sql('
            SELECT COUNT(*) FROM {usr} u INNER JOIN {usr_institution} i ON u.id = i.usr
            WHERE i.institution = ? AND u.deleted = 0', array($institution->name));
        if ($members + count($CSVDATA) > $maxusers) {
            $SESSION->add_error_msg(get_string('uploadcsvfailedusersexceedmaxallowed', 'admin'));
            redirect('/admin/users/uploadcsv.php');
        }
    }
    if ($values['updateusers']) {
        log_info('Updating users from the CSV file');
    } else {
        log_info('Inserting users from the CSV file');
    }
    db_begin();
    $addedusers = array();
    $cfgsendemail = get_config('sendemail');
    if (empty($values['emailusers'])) {
        // Temporarily disable email sent during user creation, e.g. institution membership
        $GLOBALS['CFG']->sendemail = false;
    }
    $key = 0;
    $steps_total = $values['updateusers'] ? 5 : 4;
    $steps_done = $steps_total - 3;
    $num_lines = sizeof($CSVDATA);
    foreach ($CSVDATA as $record) {
        if (!($key % 25)) {
            // This part has three times the weight of the other two steps.
            set_progress_info('uploaduserscsv', $num_lines * $steps_done + $key * 3, $num_lines * $steps_total, get_string('committingchanges', 'admin'));
        }
        $key++;
        $user = new StdClass();
        foreach ($FORMAT as $field) {
            if ($field == 'username' || $field == 'firstname' || $field == 'lastname' || $field == 'password' || $field == 'email' || $field == 'studentid' || $field == 'preferredname') {
                $user->{$field} = $record[$formatkeylookup[$field]];
            }
        }
        $user->authinstance = $authinstance;
        if ($USER->get('admin') || get_config_plugin('artefact', 'file', 'institutionaloverride')) {
            $user->quota = $values['quota'];
        }
        $profilefields = new StdClass();
        $remoteuser = null;
        foreach ($FORMAT as $field) {
            if ($field == 'username' || $field == 'password') {
                continue;
            }
            if ($field == 'remoteuser') {
                if (!empty($record[$formatkeylookup[$field]])) {
                    $remoteuser = $record[$formatkeylookup[$field]];
                }
                continue;
            }
            $profilefields->{$field} = $record[$formatkeylookup[$field]];
        }
        if (!$values['updateusers'] || !isset($UPDATES[$user->username])) {
            $user->passwordchange = (int) $values['forcepasswordchange'];
            $user->id = create_user($user, $profilefields, $institution, $authrecord, $remoteuser, $values, true);
            $addedusers[] = $user;
            log_debug('added user ' . $user->username);
        } else {
            if (isset($UPDATES[$user->username])) {
                $updated = update_user($user, $profilefields, $remoteuser, $values, true, true);
                if (empty($updated)) {
                    // Nothing changed for this user
                    unset($UPDATES[$user->username]);
                } else {
                    $UPDATES[$user->username] = $updated;
                    log_debug('updated user ' . $user->username . ' (' . implode(', ', array_keys($updated)) . ')');
                }
            }
        }
        set_time_limit(10);
    }
    db_commit();
    // Reenable email
    set_config('sendemail', $cfgsendemail);
    // Only send e-mail to users after we're sure they have been inserted
    // successfully
    $straccountcreatedtext = $values['forcepasswordchange'] ? 'accountcreatedchangepasswordtext' : 'accountcreatedtext';
    $straccountcreatedhtml = $values['forcepasswordchange'] ? 'accountcreatedchangepasswordhtml' : 'accountcreatedhtml';
    if ($values['emailusers'] && $addedusers) {
        foreach ($addedusers as $user) {
            $failedusers = array();
            try {
                email_user($user, null, get_string('accountcreated', 'mahara', get_config('sitename')), get_string($straccountcreatedtext, 'mahara', $user->firstname, get_config('sitename'), $user->username, $user->password, get_config('wwwroot'), get_config('sitename')), get_string($straccountcreatedhtml, 'mahara', $user->firstname, get_config('wwwroot'), get_config('sitename'), $user->username, $user->password, get_config('wwwroot'), get_config('wwwroot'), get_config('sitename')));
            } catch (EmailException $e) {
                log_info($e->getMessage());
                $failedusers[] = $user;
            }
        }
        if ($failedusers) {
            $message = get_string('uploadcsvsomeuserscouldnotbeemailed', 'admin') . "\n<ul>\n";
            foreach ($failedusers as $user) {
                $message .= '<li>' . full_name($user) . ' &lt;' . hsc($user->email) . "&gt;</li>\n";
            }
            $message .= "</ul>\n";
            $SESSION->add_info_msg($message, false);
        }
    }
    log_info('Added ' . count($addedusers) . ' users, updated ' . count($UPDATES) . ' users.');
    $SESSION->add_ok_msg(get_string('csvfileprocessedsuccessfully', 'admin'));
    if ($UPDATES) {
        $updatemsg = smarty_core();
        $updatemsg->assign('added', count($addedusers));
        $updatemsg->assign('updates', $UPDATES);
        $SESSION->add_info_msg($updatemsg->fetch('admin/users/csvupdatemessage.tpl'), false);
    } else {
        $SESSION->add_ok_msg(get_string('numbernewusersadded', 'admin', count($addedusers)));
    }
    set_progress_done('uploaduserscsv');
    redirect('/admin/users/uploadcsv.php');
}
예제 #8
0
파일: user.php 프로젝트: patkira/mahara
/**
 * function to format a users name when there is no user to look at them
 * ie when display_name is not going to work..
 */
function display_default_name($user)
{
    $user = get_user_for_display($user);
    return empty($user->preferredname) ? full_name($user) : $user->preferredname;
}
예제 #9
0
파일: lib.php 프로젝트: rboyatt/mahara
 private function build_index_page($summaries)
 {
     $smarty = $this->get_smarty();
     $smarty->assign('page_heading', full_name($this->get('user')));
     $smarty->assign('summaries', $summaries);
     $content = $smarty->fetch('export:html:index.tpl');
     if (!file_put_contents($this->exportdir . '/' . $this->rootdir . '/index.html', $content)) {
         throw new SystemException("Could not create index.html for the export");
     }
 }
예제 #10
0
파일: edit.php 프로젝트: Br3nda/mahara
    throw new AccessDeniedException(get_string('canteditsubmitted', 'view', $submittedto['name']));
}
$group = $view->get('group');
$institution = $view->get('institution');
View::set_nav($group, $institution);
$new = param_boolean('new', 0);
if ($new) {
    define('TITLE', get_string('createviewsteptwo', 'view'));
} else {
    define('TITLE', get_string('editviewdetails', 'view', $view->get('title')));
}
$heading = TITLE;
// for the smarty template
require_once 'pieforms/pieform.php';
$formatstring = '%s (%s)';
$ownerformatoptions = array(FORMAT_NAME_FIRSTNAME => sprintf($formatstring, get_string('firstname'), $USER->get('firstname')), FORMAT_NAME_LASTNAME => sprintf($formatstring, get_string('lastname'), $USER->get('lastname')), FORMAT_NAME_FIRSTNAMELASTNAME => sprintf($formatstring, get_string('fullname'), full_name()));
$preferredname = $USER->get('preferredname');
if ($preferredname !== '') {
    $ownerformatoptions[FORMAT_NAME_PREFERREDNAME] = sprintf($formatstring, get_string('preferredname'), $preferredname);
}
$studentid = (string) get_field('artefact', 'title', 'owner', $USER->get('id'), 'artefacttype', 'studentid');
if ($studentid !== '') {
    $ownerformatoptions[FORMAT_NAME_STUDENTID] = sprintf($formatstring, get_string('studentid'), $studentid);
}
$ownerformatoptions[FORMAT_NAME_DISPLAYNAME] = sprintf($formatstring, get_string('displayname'), display_name($USER));
$editview = array('name' => 'editview', 'method' => 'post', 'autofocus' => 'title', 'plugintype' => 'core', 'pluginname' => 'view', 'elements' => array('id' => array('type' => 'hidden', 'value' => $view->get('id')), 'type' => array('type' => 'hidden', 'value' => 'portfolio'), 'new' => array('type' => 'hidden', 'value' => $new), 'title' => array('type' => 'text', 'title' => get_string('title', 'view'), 'defaultvalue' => $view->get('title'), 'rules' => array('required' => true)), 'description' => array('type' => 'wysiwyg', 'title' => get_string('description', 'view'), 'rows' => 10, 'cols' => 70, 'defaultvalue' => $view->get('description')), 'tags' => array('type' => 'tags', 'title' => get_string('tags'), 'description' => get_string('tagsdescprofile'), 'defaultvalue' => $view->get('tags'), 'help' => true)));
if (!($group || $institution)) {
    $default = $view->get('ownerformat');
    if (!$default) {
        $default = FORMAT_NAME_DISPLAYNAME;
    }
예제 #11
0
파일: list.php 프로젝트: hasithakj/sep
                    </div><!-- /col-sm-1 -->

                    <div class="col-sm-10">
                        <div class="panel panel-default">
                            <div class="panel-heading">
                                <a href="<?php 
    echo base_url("index.php/inbox/read/{$conversation->conversation_id}");
    ?>
">
                                    <strong><?php 
    echo $conversation->subject;
    ?>
</strong><br />
                                </a>
                                <span class="text-muted"><?php 
    echo full_name($other_user);
    ?>
</span>
                            </div>
                            <div class="panel-body">
                                <?php 
    echo last_message($conversation->conversation_id);
    ?>
                            </div><!-- /panel-body -->
                            <div class="panel-footer text-right">
                                <?php 
    echo date('l jS \\of F Y h:i:s A', strtotime($conversation->last_updated_time));
    ?>
                            </div>
                        </div><!-- /panel panel-default -->
                    </div><!-- /col-sm-5 -->
예제 #12
0
/**
 *
 * @package    mahara
 * @subpackage core
 * @author     Catalyst IT Ltd
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
 * @copyright  For copyright information on Mahara, please see the README file distributed with this software.
 *
 */
define('INTERNAL', 1);
define('MENUITEM', 'settings/preferences');
require dirname(dirname(__FILE__)) . '/init.php';
define('TITLE', get_string('deleteaccount', 'account'));
require_once 'pieforms/pieform.php';
if (!$USER->can_delete_self()) {
    throw new AccessDeniedException(get_string('accessdenied', 'error'));
}
$deleteform = pieform(array('name' => 'account_delete', 'plugintype' => 'core', 'pluginname' => 'account', 'elements' => array('submit' => array('type' => 'submit', 'value' => get_string('deleteaccount', 'mahara', display_username($USER), full_name($USER))))));
function account_delete_submit(Pieform $form, $values)
{
    global $SESSION, $USER;
    $userid = $USER->get('id');
    $USER->logout();
    delete_user($userid);
    $SESSION->add_ok_msg(get_string('accountdeleted', 'account'));
    redirect('/index.php');
}
$smarty = smarty();
$smarty->assign('form', $deleteform);
$smarty->display('account/delete.tpl');
/**
 * This function logs to error_log and to the log table that an infected file has been found and what's happened to it.
 *
 * @param string $oldfilepath Full path to the infected file before it was moved.
 * @param string $newfilepath Full path to the infected file since it was moved to the quarantine directory (if the file was deleted, leave empty).
 * @param int $userid The user id of the user who uploaded the file.
 */
function clam_log_infected($oldfilepath = '', $newfilepath = '', $userid = 0)
{
    global $USER;
    $username = $USER->get('username') . ' (' . full_name() . ')';
    $errorstr = 'Clam AV has found a file that is infected with a virus. It was uploaded by ' . full_name() . (empty($oldfilepath) ? '. The infected file was caught on upload (' . $oldfilepath . ')' : '. The original file path of the infected file was ' . $oldfilepath) . (empty($newfilepath) ? '. The file has been deleted ' : '. The file has been moved to a quarantine directory and the new path is ' . $newfilepath);
    log_debug($errorstr);
}
예제 #14
0
 case 'headers_table':
     // нет параметров, обязателен common.php
     //////////////////////////////////////////////////
     if ($mbi) {
         $r = array();
         for ($k = 1; $k <= $nomsgi; $k++) {
             $header = imap_header($mbi, $k);
             if (isset($highlight_to[$user])) {
                 $head['to'] = full_name($header->to[0], $highlight_to[$user]);
             } else {
                 $head['to'] = full_name($header->to[0]);
             }
             if (isset($highlight_from[$user])) {
                 $head['from'] = full_name($header->from[0], $highlight_from[$user]);
             } else {
                 $head['from'] = full_name($header->from[0]);
             }
             if (isset($header->subject)) {
                 $head['subject'] = htmlspecialchars(mp_decode($header->subject));
             } else {
                 $head['subject'] = '<i>No subject</i>';
             }
             $head['Size'] = $header->Size;
             $head['no'] = $header->Msgno;
             $r[$k] = $head;
         }
         // for
         print_rt($r);
     }
     // if
     break;
예제 #15
0
                    <div class="col-sm-1">
                        <div class="thumbnail">
                            <a href="#">
                                <img class="img-responsive user-photo" src="<?php 
    echo user_img_url($message->sender_id);
    ?>
">
                            </a>
                        </div><!-- /thumbnail -->
                    </div><!-- /col-sm-1 -->

                    <div class="col-sm-11">
                        <div class="panel panel-default">
                            <div class="panel-heading">
                                <strong><?php 
    echo full_name($message->sender_id);
    ?>
</strong> <span class="text-muted"><?php 
    echo $message->created_time;
    ?>
</span>
                            </div>
                            <div class="panel-body">
                                <?php 
    echo $message->content;
    ?>
                            </div><!-- /panel-body -->
                        </div><!-- /panel panel-default -->
                    </div><!-- /col-sm-5 -->
                </div><!-- /row -->
            <?php