Ejemplo n.º 1
0
         profile_move_category($id, $dir);
     }
     redirect($redirect);
     break;
 case 'movefield':
     $id = required_param('id', PARAM_INT);
     $dir = required_param('dir', PARAM_ALPHA);
     if (confirm_sesskey()) {
         profile_move_field($id, $dir);
     }
     redirect($redirect);
     break;
 case 'deletecategory':
     $id = required_param('id', PARAM_INT);
     if (confirm_sesskey()) {
         profile_delete_category($id);
     }
     redirect($redirect, get_string('deleted'));
     break;
 case 'deletefield':
     $id = required_param('id', PARAM_INT);
     $confirm = optional_param('confirm', 0, PARAM_BOOL);
     // If no userdata for profile than don't show confirmation.
     $datacount = $DB->count_records('user_info_data', array('fieldid' => $id));
     if ((data_submitted() and $confirm or $datacount === 0) and confirm_sesskey()) {
         profile_delete_field($id);
         redirect($redirect, get_string('deleted'));
     }
     // Ask for confirmation, as there is user data available for field.
     $fieldname = $DB->get_field('user_info_field', 'name', array('id' => $id));
     $optionsyes = array('id' => $id, 'confirm' => 1, 'action' => 'deletefield', 'sesskey' => sesskey());
Ejemplo n.º 2
0
     $name = $company->name;
     echo $OUTPUT->heading(get_string('deletecompany', 'block_iomad_company_admin'), 2, 'headingblock header');
     $optionsyes = array('delete' => $delete, 'confirm' => md5($delete), 'sesskey' => sesskey());
     echo $OUTPUT->confirm(get_string('companydeletecheckfull', 'block_iomad_company_admin', "'{$name}'"), new moodle_url('company_list.php', $optionsyes), 'company_list.php');
     echo $OUTPUT->footer();
     die;
 } else {
     if (data_submitted()) {
         $a2bdcompany = new company($delete);
         $userids = $a2bdcompany->get_user_ids();
         $transaction = $DB->start_delegated_transaction();
         if ($DB->delete_records('company', array('id' => $delete))) {
             // Delete the company profile category.
             if ($category = $DB->get_record('user_info_category', array('name' => $company->shortname))) {
                 // Remove the category.
                 profile_delete_category($ccategory->id);
             }
             // Delete company users as well.
             foreach ($userids as $userid) {
                 $user = $DB->get_record('user', array('id' => $userid, 'deleted' => 0), '*', MUST_EXIST);
                 // Must not allow deleting of admins or self!!!
                 if (is_siteadmin($user)) {
                     throw new moodle_exception('useradminodelete', 'error');
                 }
                 if ($USER->id == $user->id) {
                     throw new moodle_exception('usernotdeletederror', 'error');
                 }
                 user_delete_user($user);
             }
             $transaction->allow_commit();
             redirect($returnurl);