/**
  * Updates a contact's details in the DB according to the
  * values passed via AJAX
  * @global object $USER Moodle user object (session persistent)
  * @param int $addressbookId ID of addressbook to update
  * @param int $contactId ID of contact to update
  * @param string $contactFirstName Contact's first name
  * @param string $contactLastName Contact's last name
  * @param string $contactCompany Contact's employer
  * @param string $contactPhoneNumber Contact's phone number
  * @return string JSON-encoded response to request
  * @throws MoodletxtAJAXException
  * @version 2012061801
  * @since 2012090501
  */
 private function updateContact($addressbookId, $contactId, $contactFirstName, $contactLastName, $contactCompany, $contactPhoneNumber)
 {
     global $USER;
     // Check that user owns DB
     if (!$this->addressbookDAO->checkAddressbookOwnership($addressbookId, $USER->id)) {
         throw new MoodletxtAJAXException(get_string('errorbooknotowned', 'block_moodletxt'), MoodletxtAJAXException::$ERROR_NOT_ADDRESSBOOK_OWNER, null, false);
     }
     // Get record from DB and update it
     try {
         $contact = $this->addressbookDAO->getAddressbookContactById($addressbookId, $contactId);
         $contact->setFirstName($contactFirstName);
         $contact->setLastName($contactLastName);
         $contact->setCompanyName($contactCompany);
         $contact->setRecipientNumber(new MoodletxtPhoneNumber($contactPhoneNumber));
         $this->addressbookDAO->saveContact($contact);
     } catch (InvalidArgumentException $ex) {
         throw new MoodletxtAJAXException(get_string('errorbadcontactid', 'block_moodletxt'), MoodletxtAJAXException::$ERROR_CODE_BAD_CONTACT_ID, null, false);
     }
     return $this->buildResponse($contact);
 }
示例#2
0
 */
require_once '../../config.php';
require_once $CFG->dirroot . '/blocks/moodletxt/dao/MoodletxtAddressbookDAO.php';
require_once $CFG->dirroot . '/blocks/moodletxt/forms/MoodletxtGroupAddForm.php';
require_once $CFG->dirroot . '/blocks/moodletxt/forms/MoodletxtGroupEditForm.php';
require_once $CFG->dirroot . '/blocks/moodletxt/forms/MoodletxtGroupDeleteForm.php';
require_once $CFG->dirroot . '/blocks/moodletxt/forms/renderers/QuickFormRendererWithSlides.php';
$courseId = required_param('course', PARAM_INT);
$instanceId = required_param('instance', PARAM_INT);
$addressbookId = required_param('addressbook', PARAM_INT);
require_login($courseId, false);
$blockcontext = context_block::instance($instanceId);
require_capability('block/moodletxt:addressbooks', $blockcontext, $USER->id);
// OK, so you're legit. Let's load DAOs
$addressbookDAO = new MoodletxtAddressbookDAO();
if (!$addressbookDAO->checkAddressbookOwnership($addressbookId, $USER->id)) {
    print_error('errorbadbookid', 'block_moodletxt');
}
$addressbook = $addressbookDAO->getAddressbookById($addressbookId, $USER->id);
// SETUP PAGE
$PAGE->set_url('/blocks/moodletxt/addressbook_groups.php');
$PAGE->set_title(get_string('titlegroupsmanage', 'block_moodletxt') . ' "' . $addressbook->getName() . '"');
$PAGE->set_heading(get_string('headergroupsmanage', 'block_moodletxt'));
$PAGE->set_pagelayout('incourse');
$PAGE->set_button('');
// Clear editing button
$addressbookNav = new moodle_url('/blocks/moodletxt/addressbooks.php', array('course' => $courseId, 'instance' => $instanceId));
$addressbookEditNav = new moodle_url('/blocks/moodletxt/addressbook_view.php', array('course' => $courseId, 'instance' => $instanceId, 'addressbook' => $addressbook->getId()));
$PAGE->navbar->add(get_string('navmoodletxt', 'block_moodletxt'), null, navigation_node::TYPE_CUSTOM, 'moodletxt');
$PAGE->navbar->add(get_string('navaddressbooks', 'block_moodletxt'), $addressbookNav, navigation_node::TYPE_CUSTOM, 'moodletxt');
$PAGE->navbar->add($addressbook->getName(), $addressbookEditNav, navigation_node::TYPE_CUSTOM, 'moodletxt');
示例#3
0
$formData = $addressbookForm->get_data();
if ($formData != null) {
    $formData = $addressbookForm->cleanupFormData($formData);
    if ($formData->newAddressbookName != '' && $formData->submitButton == get_string('buttonadd', 'block_moodletxt')) {
        $newAddressbook = new MoodletxtAddressbook((int) $USER->id, $formData->newAddressbookName, $formData->newAddressbookType);
        $addressbookDAO->saveAddressbook($newAddressbook);
        // Drop new addressbook into form
        $addressbookForm->get_element('existingAddressbook')->addOption($newAddressbook->getName(), $newAddressbook->getId());
        $addressbookForm->get_element('mergeAddressbook')->addOption($newAddressbook->getName(), $newAddressbook->getId());
        $addressbookForm->clearSubmittedValues();
        $notifications .= $output->notification(get_string('notifyaddressbookadded', 'block_moodletxt'), 'notifysuccess');
    }
    if ($formData->existingAddressbook > 0 && $formData->submitButton == get_string('buttondeleteormerge', 'block_moodletxt')) {
        // Grab addressbook from database to check ownership (security measure)
        // (This should technically never happen, as PEAR's form library validates select values)
        if (!$addressbookDAO->checkAddressbookOwnership($formData->existingAddressbook, $USER->id)) {
            $notifications .= $output->notification(get_string('errorbooknotowned', 'block_moodletxt'), 'notifyproblem');
        } else {
            // If-else technically isn't needed, as merge param is optional, but this just feels...safer
            if ($formData->deleteExistingContacts == 'merge' && $formData->mergeAddressbook > 0) {
                $addressbookDAO->deleteOrMergeAddressbookById($formData->existingAddressbook, $formData->mergeAddressbook);
            } else {
                $addressbookDAO->deleteOrMergeAddressbookById($formData->existingAddressbook);
            }
            $notifications .= $output->notification(get_string('notifyaddressbookdeleted', 'block_moodletxt'), 'notifysuccess');
            $addressbookForm->get_element('existingAddressbook')->removeOption($formData->existingAddressbook);
            $addressbookForm->get_element('mergeAddressbook')->removeOption($formData->existingAddressbook);
            $addressbookForm->clearSubmittedValues();
        }
    }
}