Beispiel #1
0
 /**
  * Creates a folder artefact based on the given entry.
  *
  * @param SimpleXMLElement $entry The entry to base the folder's data on
  * @param PluginImport $importer  The importer
  * @param int $parent             The ID of the parent artefact for this folder
  * @throws ImportException If the given entry is not detected as being a folder
  * @return int The ID of the folder artefact created
  */
 private static function create_folder(SimpleXMLElement $entry, PluginImport $importer, $parent = null)
 {
     if (!self::is_folder($entry, $importer)) {
         throw new ImportException($importer, "create_folder(): Cannot create a folder artefact from an entry we don't recognise as a folder");
     }
     $folder = new ArtefactTypeFolder();
     $folder->set('title', (string) $entry->title);
     $folder->set('description', PluginImportLeap::get_entry_content($entry, $importer));
     if ($published = strtotime((string) $entry->published)) {
         $folder->set('ctime', $published);
     }
     if ($updated = strtotime((string) $entry->updated)) {
         $folder->set('mtime', $updated);
     }
     $folder->set('owner', $importer->get('usr'));
     $folder->set('tags', PluginImportLeap::get_entry_tags($entry));
     if ($parent) {
         $folder->set('parent', $parent);
     }
     $folder->commit();
     return $folder->get('id');
 }
Beispiel #2
0
 /**
  * Render import entry requests for Mahara plans and their tasks
  * @param PluginImportLeap $importer
  * @return HTML code for displaying plans and choosing how to import them
  */
 public static function render_import_entry_requests(PluginImportLeap $importer)
 {
     $importid = $importer->get('importertransport')->get('importid');
     // Get import entry requests for Mahara plans
     $entryplans = array();
     if ($ierplans = get_records_select_array('import_entry_requests', 'importid = ? AND entrytype = ?', array($importid, 'plan'))) {
         foreach ($ierplans as $ierplan) {
             $plan = unserialize($ierplan->entrycontent);
             $plan['id'] = $ierplan->id;
             $plan['decision'] = $ierplan->decision;
             if (is_string($ierplan->duplicateditemids)) {
                 $ierplan->duplicateditemids = unserialize($ierplan->duplicateditemids);
             }
             if (is_string($ierplan->existingitemids)) {
                 $ierplan->existingitemids = unserialize($ierplan->existingitemids);
             }
             $plan['disabled'][PluginImport::DECISION_IGNORE] = false;
             $plan['disabled'][PluginImport::DECISION_ADDNEW] = false;
             $plan['disabled'][PluginImport::DECISION_APPEND] = true;
             $plan['disabled'][PluginImport::DECISION_REPLACE] = true;
             if (!empty($ierplan->duplicateditemids)) {
                 $duplicated_item = artefact_instance_from_id($ierplan->duplicateditemids[0]);
                 $plan['duplicateditem']['id'] = $duplicated_item->get('id');
                 $plan['duplicateditem']['title'] = $duplicated_item->get('title');
                 $res = $duplicated_item->render_self(array());
                 $plan['duplicateditem']['html'] = $res['html'];
             } else {
                 if (!empty($ierplan->existingitemids)) {
                     foreach ($ierplan->existingitemids as $id) {
                         $existing_item = artefact_instance_from_id($id);
                         $res = $existing_item->render_self(array());
                         $plan['existingitems'][] = array('id' => $existing_item->get('id'), 'title' => $existing_item->get('title'), 'html' => $res['html']);
                     }
                 }
             }
             // Get import entry requests of tasks in the plan
             $entrytasks = array();
             if ($iertasks = get_records_select_array('import_entry_requests', 'importid = ? AND entrytype = ? AND entryparent = ?', array($importid, 'task', $ierplan->entryid))) {
                 foreach ($iertasks as $iertask) {
                     $task = unserialize($iertask->entrycontent);
                     $task['id'] = $iertask->id;
                     $task['decision'] = $iertask->decision;
                     $task['completiondate'] = format_date($task['completiondate'], 'strftimedate');
                     $task['disabled'][PluginImport::DECISION_IGNORE] = false;
                     $task['disabled'][PluginImport::DECISION_ADDNEW] = false;
                     $task['disabled'][PluginImport::DECISION_APPEND] = true;
                     $task['disabled'][PluginImport::DECISION_REPLACE] = true;
                     $entrytasks[] = $task;
                 }
             }
             $plan['entrytasks'] = $entrytasks;
             $entryplans[] = $plan;
         }
     }
     $smarty = smarty_core();
     $smarty->assign_by_ref('displaydecisions', $importer->get('displaydecisions'));
     $smarty->assign_by_ref('entryplans', $entryplans);
     return $smarty->fetch('artefact:plans:import/plans.tpl');
 }
 /**
  * Creates a plan or task from the given entry
  *
  * @param SimpleXMLElement $entry    The entry to create the plan or task from
  * @param PluginImportLeap $importer The importer
  * @return array A list of artefact IDs created, to be used with the artefact mapping.
  */
 private static function create_plan(SimpleXMLElement $entry, PluginImportLeap $importer)
 {
     // First decide if it's going to be a plan or a task depending
     // on whether it has any ancestral plans.
     if (self::get_ancestor_entryid($entry, $importer)) {
         $artefact = new ArtefactTypeTask();
     } else {
         $artefact = new ArtefactTypePlan();
     }
     $artefact->set('title', (string) $entry->title);
     $artefact->set('description', PluginImportLeap::get_entry_content($entry, $importer));
     $artefact->set('owner', $importer->get('usr'));
     if (isset($entry->author->name) && strlen($entry->author->name)) {
         $artefact->set('authorname', $entry->author->name);
     } else {
         $artefact->set('author', $importer->get('usr'));
     }
     if ($published = strtotime((string) $entry->published)) {
         $artefact->set('ctime', $published);
     }
     if ($updated = strtotime((string) $entry->updated)) {
         $artefact->set('mtime', $updated);
     }
     $artefact->set('tags', PluginImportLeap::get_entry_tags($entry));
     // Set completiondate and completed status if we can find them
     if ($artefact instanceof ArtefactTypeTask) {
         $namespaces = $importer->get_namespaces();
         $ns = $importer->get_leap2a_namespace();
         $dates = PluginImportLeap::get_leap_dates($entry, $namespaces, $ns);
         if (!empty($dates['target']['value'])) {
             $completiondate = strtotime($dates['target']['value']);
         }
         $artefact->set('completiondate', empty($completiondate) ? $artefact->get('mtime') : $completiondate);
         if ($entry->xpath($namespaces[$ns] . ':status[@' . $namespaces[$ns] . ':stage="completed"]')) {
             $artefact->set('completed', 1);
         }
     }
     $artefact->commit();
     return array($artefact->get('id'));
 }
 /**
  * Given an entry, see if it's attached to one of the special selections 
  * representing a Mahara resume group. If so, return the display order it 
  * should have in that group.
  *
  * We look for the special Mahara selections only, because entries could be 
  * in more than one selection, with different display orders in each.
  *
  * @param SimpleXMLElement $entry    The entry to check
  * @param PluginImportLeap $importer The importer
  * @param string $selectiontype      The type of selection we're checking to 
  *                                   see if the entry is part of - one of the 
  *                                   special Mahara resume selections
  * @return int The display order of the element in the selection, should it 
  *             be in one - else null
  */
 private static function get_display_order_for_entry(SimpleXMLElement $entry, PluginImportLeap $importer, $selectiontype)
 {
     static $cache = array();
     $found = false;
     foreach ($entry->link as $link) {
         if ($importer->curie_equals($link['rel'], $importer->get_leap2a_namespace(), 'is_part_of') && isset($link['href'])) {
             $href = (string) $link['href'];
             if (isset($cache[$href])) {
                 $found = true;
             } else {
                 if ($potentialselection = $importer->get_entry_by_id($href)) {
                     if (PluginImportLeap::is_rdf_type($potentialselection, $importer, 'selection')) {
                         if (PluginImportLeap::is_correct_category_scheme($potentialselection, $importer, 'selection_type', 'Grouping')) {
                             if (count($potentialselection->xpath('mahara:artefactplugin[@mahara:type="' . $selectiontype . '"]')) == 1) {
                                 $cache[$href] = true;
                                 $found = true;
                             }
                         }
                     }
                 }
             }
             if ($found) {
                 $leapattributes = $importer->get_attributes($link, $importer->get_leap2a_namespace());
                 $displayorder = isset($leapattributes['display_order']) && intval($leapattributes['display_order']) > 0 ? $leapattributes['display_order'] : '';
                 return $displayorder;
             }
         }
     }
 }
 public static function get_comment_instance(SimpleXMLElement $entry, PluginImportLeap $importer)
 {
     $artefactids = $importer->get_artefactids_imported_by_entryid((string) $entry->id);
     return new ArtefactTypeComment($artefactids[0]);
 }
Beispiel #6
0
 /**
  * Custom hook to import data about the feed author.
  *
  * If we have a persondata element for them, we can import lots of 
  * different information about them into Mahara's profile section. 
  * Otherwise, we can only import some very basic information from the 
  * <author> element.
  *
  * @param PluginImport $importer The importer
  */
 public static function import_author_data(PluginImport $importer)
 {
     if (self::$persondataid) {
         // Grab all the leap:persondata elements and import them
         $person = $importer->get_entry_by_id(self::$persondataid);
         // The introduction comes from the entry content
         $introduction = new ArtefactTypeIntroduction(0, array('owner' => $importer->get('usr')));
         $introduction->set('title', PluginImportLeap::get_entry_content($person, $importer));
         $introduction->commit();
         // Most of the rest of the profile data comes from leap:persondata elements
         $persondata = $person->xpath('leap:persondata');
         foreach ($persondata as $item) {
             $leapattributes = array();
             foreach ($item->attributes(PluginImportLeap::NS_LEAP) as $key => $value) {
                 $leapattributes[$key] = (string) $value;
             }
             if (!isset($leapattributes['field'])) {
                 // 'Field' is required
                 // http://wiki.cetis.ac.uk/2009-03/LEAP2A_personal_data#field
                 $importer->trace('WARNING: persondata element did not have leap:field attribute');
                 continue;
             }
             self::import_persondata($importer, $item, $leapattributes);
         }
         // The information about someone's name is much more comprehensive
         // in LEAP than what Mahara has, so we have to piece it together
         self::import_namedata($importer, $persondata);
         // People can have address info associated with them
         $addressdata = $person->xpath('leap:spatial');
         if (count($addressdata) == 1) {
             self::import_addressdata($importer, $addressdata[0]);
         }
     } else {
         $author = $importer->get('xml')->xpath('//a:feed/a:author[1]');
         $author = $author[0];
         if (!isset($author->name)) {
             throw new ImportException($importer, 'TODO: get_string: <author> must include <name> - http://wiki.cetis.ac.uk/2009-03/LEAP2A_relationships#Author');
         }
         $name = (string) $author->name;
         if (false !== strpos($name, ' ')) {
             list($firstname, $lastname) = explode(' ', $name, 2);
             self::create_artefact($importer, 'firstname', trim($firstname));
             self::create_artefact($importer, 'lastname', trim($lastname));
         } else {
             // Blatant assumtion that the <name> is a first name
             self::create_artefact($importer, 'firstname', trim($name));
         }
         if (isset($author->email)) {
             self::create_artefact($importer, 'email', (string) $author->email);
         }
         if (isset($author->uri)) {
             $uri = (string) $author->uri;
             if (preg_match('#^https?://#', $uri)) {
                 self::create_artefact($importer, 'officialwebsite', (string) $author->uri);
             }
         }
     }
 }
Beispiel #7
0
 /**
  * Render import entry requests for Mahara user's profile fields
  * @param PluginImportLeap $importer
  * @return HTML code for displaying user's profile fields and choosing how to import them
  */
 public static function render_import_entry_requests(PluginImportLeap $importer)
 {
     $importid = $importer->get('importertransport')->get('importid');
     $profilefields = array('profile' => array('legend' => get_string('aboutme', 'artefact.internal'), 'fields' => array('firstname', 'lastname', 'studentid', 'preferredname', 'introduction')), 'contact' => array('legend' => get_string('contact', 'artefact.internal'), 'fields' => array('email', 'maildisabled', 'officialwebsite', 'personalwebsite', 'blogaddress', 'address', 'town', 'city', 'country', 'homenumber', 'businessnumber', 'mobilenumber', 'faxnumber')), 'messaging' => array('legend' => get_string('messaging', 'artefact.internal'), 'fields' => array('socialprofile')), 'general' => array('legend' => get_string('general'), 'fields' => array('occupation', 'industry')));
     // Get import entry requests for Mahara profile fields
     $profilegroups = array();
     foreach ($profilefields as $gr_key => $group) {
         $profilegroup = array();
         $profilegroup['id'] = $gr_key;
         $profilegroup['legend'] = $group['legend'];
         foreach ($group['fields'] as $f) {
             if ($iers = get_records_select_array('import_entry_requests', 'importid = ? AND entrytype = ?', array($importid, $f))) {
                 $profilefieldvalues = array();
                 foreach ($iers as $ier) {
                     $profilefieldvalue = unserialize($ier->entrycontent);
                     $profilefieldvalue['id'] = $ier->id;
                     $profilefieldvalue['decision'] = $ier->decision;
                     $classname = generate_artefact_class_name($f);
                     $profilefieldvalue['html'] = $classname::render_import_entry_request($profilefieldvalue);
                     if (is_string($ier->duplicateditemids)) {
                         $ier->duplicateditemids = unserialize($ier->duplicateditemids);
                     }
                     if (is_string($ier->existingitemids)) {
                         $ier->existingitemids = unserialize($ier->existingitemids);
                     }
                     $profilefieldvalue['disabled'][PluginImport::DECISION_IGNORE] = false;
                     if (!empty($ier->duplicateditemids)) {
                         $duplicated_pfield = artefact_instance_from_id($ier->duplicateditemids[0]);
                         $profilefieldvalue['duplicateditem']['id'] = $duplicated_pfield->get('id');
                         $res = $duplicated_pfield->render_self(array());
                         $profilefieldvalue['duplicateditem']['html'] = $res['html'];
                         $profilefieldvalue['disabled'][PluginImport::DECISION_ADDNEW] = true;
                         $profilefieldvalue['disabled'][PluginImport::DECISION_APPEND] = true;
                         $profilefieldvalue['disabled'][PluginImport::DECISION_REPLACE] = true;
                     } else {
                         if (!empty($ier->existingitemids)) {
                             foreach ($ier->existingitemids as $id) {
                                 $existing_pfield = artefact_instance_from_id($id);
                                 $res = $existing_pfield->render_self(array());
                                 $profilefieldvalue['existingitems'][] = array('id' => $existing_pfield->get('id'), 'html' => $res['html']);
                             }
                             if ($f == 'email') {
                                 $profilefieldvalue['disabled'][PluginImport::DECISION_ADDNEW] = false;
                                 $profilefieldvalue['disabled'][PluginImport::DECISION_APPEND] = true;
                                 $profilefieldvalue['disabled'][PluginImport::DECISION_REPLACE] = true;
                             } else {
                                 $is_singular = call_static_method(generate_artefact_class_name($ier->entrytype), 'is_singular');
                                 $profilefieldvalue['disabled'][PluginImport::DECISION_ADDNEW] = $is_singular;
                                 $profilefieldvalue['disabled'][PluginImport::DECISION_APPEND] = !$is_singular;
                                 $profilefieldvalue['disabled'][PluginImport::DECISION_REPLACE] = !$is_singular;
                             }
                         } else {
                             $profilefieldvalue['disabled'][PluginImport::DECISION_ADDNEW] = false;
                             $profilefieldvalue['disabled'][PluginImport::DECISION_APPEND] = true;
                             $profilefieldvalue['disabled'][PluginImport::DECISION_REPLACE] = true;
                         }
                     }
                     $profilefieldvalues[] = $profilefieldvalue;
                 }
                 $profilegroup['fields'][$f] = $profilefieldvalues;
             }
         }
         $profilegroups[] = $profilegroup;
     }
     $smarty = smarty_core();
     $smarty->assign_by_ref('displaydecisions', $importer->get('displaydecisions'));
     $smarty->assign_by_ref('profilegroups', $profilegroups);
     return $smarty->fetch('artefact:internal:import/profilefields.tpl');
 }
Beispiel #8
0
 /**
  * Render import entry requests for Mahara comments
  * @param PluginImportLeap $importer
  * @return HTML code for displaying comments and choosing how to import them
  */
 public static function render_import_entry_requests(PluginImportLeap $importer)
 {
     $importid = $importer->get('importertransport')->get('importid');
     // Get import entry requests for Mahara comments
     $entrycomments = array();
     if ($iercomments = get_records_select_array('import_entry_requests', 'importid = ? AND entrytype = ?', array($importid, 'comment'))) {
         foreach ($iercomments as $iercomment) {
             $comment = unserialize($iercomment->entrycontent);
             $comment['id'] = $iercomment->id;
             $comment['decision'] = $iercomment->decision;
             $comment['disabled'][PluginImport::DECISION_IGNORE] = false;
             $comment['disabled'][PluginImport::DECISION_ADDNEW] = false;
             $comment['disabled'][PluginImport::DECISION_APPEND] = true;
             $comment['disabled'][PluginImport::DECISION_REPLACE] = true;
             $entrycomments[] = $comment;
         }
     }
     $smarty = smarty_core();
     $smarty->assign_by_ref('displaydecisions', $importer->get('displaydecisions'));
     $smarty->assign_by_ref('entrycomments', $entrycomments);
     return $smarty->fetch('artefact:comment:import/comments.tpl');
 }
Beispiel #9
0
 /**
  * Checks to see if a blogpost had out-of-line content, and if it did, 
  * attaches the generated file to it
  *
  * @param SimpleXMLElement $entry    The entry to check
  * @param PluginImportLeap $importer The importer
  */
 private static function setup_outoflinecontent_relationship(SimpleXMLElement $entry, PluginImportLeap $importer)
 {
     $artefactids = $importer->get_artefactids_imported_by_entryid((string) $entry->id);
     if (count($artefactids) == 2) {
         // In this case, a file was created as a result of
         // importing a blog entry with out-of-line content. We
         // attach the file to this post.
         $blogpost = new ArtefactTypeBlogPost($artefactids[0]);
         $blogpost->attach_file($artefactids[1]);
         $blogpost->commit();
     }
 }
Beispiel #10
0
 /**
  * Render import entry requests for Mahara annotations
  * @param PluginImportLeap $importer
  * @return HTML code for displaying annotations and choosing how to import them
  */
 public static function render_import_entry_requests(PluginImportLeap $importer)
 {
     $importid = $importer->get('importertransport')->get('importid');
     // Get import entry requests for Mahara annotations
     $entryannotations = array();
     if ($ierannotations = get_records_select_array('import_entry_requests', 'importid = ? AND entrytype = ?', array($importid, 'annotation'))) {
         foreach ($ierannotations as $ierannotation) {
             $annotation = unserialize($ierannotation->entrycontent);
             $annotation['id'] = $ierannotation->id;
             $annotation['decision'] = $ierannotation->decision;
             if (is_string($ierannotation->duplicateditemids)) {
                 $ierannotation->duplicateditemids = unserialize($ierannotation->duplicateditemids);
             }
             if (is_string($ierannotation->existingitemids)) {
                 $ierannotation->existingitemids = unserialize($ierannotation->existingitemids);
             }
             $annotation['disabled'][PluginImport::DECISION_IGNORE] = false;
             $annotation['disabled'][PluginImport::DECISION_ADDNEW] = false;
             $annotation['disabled'][PluginImport::DECISION_APPEND] = true;
             $annotation['disabled'][PluginImport::DECISION_REPLACE] = true;
             if (!empty($ierannotation->duplicateditemids)) {
                 $duplicated_annotation = artefact_instance_from_id($ierannotation->duplicateditemids[0]);
                 $annotation['duplicateditem']['id'] = $duplicated_annotation->get('id');
                 $annotation['duplicateditem']['title'] = $duplicated_annotation->get('title');
                 $res = $duplicated_annotation->render_self(array());
                 $annotation['duplicateditem']['html'] = $res['html'];
             } else {
                 if (!empty($ierannotation->existingitemids)) {
                     foreach ($ierannotation->existingitemids as $id) {
                         $existing_annotation = artefact_instance_from_id($id);
                         $res = $existing_annotation->render_self(array());
                         $annotation['existingitems'][] = array('id' => $existing_annotation->get('id'), 'title' => $existing_annotation->get('title'), 'html' => $res['html']);
                     }
                 }
             }
             // Get the feedback.
             $annotationfeedback = array();
             if ($ierannotationfeedback = get_records_select_array('import_entry_requests', 'importid = ? AND entrytype = ? AND entryparent = ?', array($importid, 'annotationfeedback', $ierannotation->entryid))) {
                 foreach ($ierannotationfeedback as $ierfeedback) {
                     $feedback = unserialize($ierfeedback->entrycontent);
                     $feedback['id'] = $ierfeedback->id;
                     $feedback['decision'] = $ierfeedback->decision;
                     if (is_string($ierfeedback->duplicateditemids)) {
                         $ierfeedback->duplicateditemids = unserialize($ierfeedback->duplicateditemids);
                     }
                     if (is_string($ierfeedback->existingitemids)) {
                         $ierfeedback->existingitemids = unserialize($ierfeedback->existingitemids);
                     }
                     $feedback['disabled'][PluginImport::DECISION_IGNORE] = false;
                     $feedback['disabled'][PluginImport::DECISION_ADDNEW] = false;
                     $feedback['disabled'][PluginImport::DECISION_APPEND] = true;
                     $feedback['disabled'][PluginImport::DECISION_REPLACE] = true;
                     if (!empty($ierfeedback->duplicateditemids)) {
                         $duplicated_feedback = artefact_instance_from_id($ierfeedback->duplicateditemids[0]);
                         $feedback['duplicateditem']['id'] = $duplicated_feedback->get('id');
                         $feedback['duplicateditem']['title'] = $duplicated_feedback->get('title');
                         $feedback['duplicateditem']['html'] = $duplicated_feedback->render_self();
                     } else {
                         if (!empty($ierfeedback->existingitemids)) {
                             foreach ($ierfeedback->existingitemids as $id) {
                                 $existing_feedback = artefact_instance_from_id($id);
                                 $feedback['existingitems'][] = array('id' => $existing_feedback->get('id'), 'title' => $existing_feedback->get('title'), 'html' => $existing_feedback->render_self());
                             }
                         }
                     }
                     $annotationfeedback[] = $feedback;
                 }
             }
             $annotation['annotationfeedback'] = $annotationfeedback;
             $entryannotations[] = $annotation;
         }
     }
     $smarty = smarty_core();
     $smarty->assign_by_ref('displaydecisions', $importer->get('displaydecisions'));
     $smarty->assign_by_ref('entryannotations', $entryannotations);
     return $smarty->fetch('artefact:annotation:import/annotations.tpl');
 }
Beispiel #11
0
 /**
  * Add import entry request for a folder artefact based on the given entry.
  *
  * @param SimpleXMLElement $entry    The entry to base the folder's data on
  * @param PluginImportLeap $importer The importer
  * @param int $parent                The ID of the parent artefact for this folder
  * @throws ImportException If the given entry is not detected as being a folder
  * @return int The ID of the folder import entry request created
  */
 private static function add_import_entry_request_folder(SimpleXMLElement $entry, PluginImportLeap $importer, $parent = null)
 {
     $config = self::get_folder_entry_data($entry, $importer, $parent);
     return PluginImportLeap::add_import_entry_request($importer->get('importertransport')->get('importid'), (string) $entry->id, self::STRATEGY_IMPORT_AS_FOLDER, 'file', $config);
 }
 /**
  * Creates an artefact in the manner required to overwrite existing profile 
  * artefacts
  *
  * @param PluginImportLeap $importer The importer
  * @param string $artefacttype        The type of artefact to create
  * @param string $title               The title for the artefact (with profile 
  *                                    fields, this is the main data)
  * @return int The ID of the artefact created
  */
 private static function create_artefact(PluginImportLeap $importer, $artefacttype, $title)
 {
     $classname = generate_artefact_class_name($artefacttype);
     $artefact = null;
     if ($artefacttype == 'email') {
         // this type is a bit special. just check if we have one with this value already
         if ($a = get_record('artefact', 'artefacttype', 'email', 'owner', $importer->get('usr'), 'title', $title)) {
             $artefact = new $classname($a->id, $a);
         }
     }
     if (empty($artefact)) {
         try {
             $artefact = artefact_instance_from_type($artefacttype, $importer->get('usr'));
         } catch (Exception $e) {
             $artefact = new $classname(0, array('owner' => $importer->get('usr')));
         }
     }
     $artefact->set('title', $title);
     $artefact->commit();
     return $artefact->get('id');
 }
function adduser_validate(Pieform $form, $values)
{
    global $USER, $TRANSPORTER;
    $authobj = AuthFactory::create($values['authinstance']);
    $institution = $authobj->institution;
    // Institutional admins can only set their own institutions' authinstances
    if (!$USER->get('admin') && !$USER->is_institutional_admin($authobj->institution)) {
        $form->set_error('authinstance', get_string('notadminforinstitution', 'admin'));
        return;
    }
    $institution = new Institution($authobj->institution);
    // Don't exceed max user accounts for the institution
    if ($institution->isFull()) {
        $form->set_error('authinstance', get_string('institutionmaxusersexceeded', 'admin'));
        return;
    }
    $username = $values['username'];
    $firstname = $values['firstname'];
    $lastname = $values['lastname'];
    $email = $values['email'];
    $password = $values['password'];
    if (method_exists($authobj, 'is_username_valid') && !$authobj->is_username_valid($username)) {
        $form->set_error('username', get_string('usernameinvalidform', 'auth.internal'));
    }
    if (!$form->get_error('username') && record_exists_select('usr', 'LOWER(username) = ?', strtolower($username))) {
        $form->set_error('username', get_string('usernamealreadytaken', 'auth.internal'));
    }
    if (method_exists($authobj, 'is_password_valid') && !$authobj->is_password_valid($password)) {
        $form->set_error('password', get_string('passwordinvalidform', 'auth.' . $authobj->type));
    }
    if (isset($_POST['createmethod']) && $_POST['createmethod'] == 'leap2a') {
        $form->set_error('firstname', null);
        $form->set_error('lastname', null);
        $form->set_error('email', null);
        if (!$values['leap2afile']) {
            $form->set_error('leap2afile', $form->i18n('rule', 'required', 'required'));
            return;
        }
        if ($values['leap2afile']['type'] == 'application/octet-stream') {
            require_once 'file.php';
            $mimetype = file_mime_type($values['leap2afile']['tmp_name']);
        } else {
            $mimetype = $values['leap2afile']['type'];
        }
        $date = time();
        $niceuser = preg_replace('/[^a-zA-Z0-9_-]/', '-', $values['username']);
        safe_require('import', 'leap');
        $fakeimportrecord = (object) array('data' => array('importfile' => $values['leap2afile']['tmp_name'], 'importfilename' => $values['leap2afile']['name'], 'importid' => $niceuser . '-' . $date, 'mimetype' => $mimetype));
        $TRANSPORTER = new LocalImporterTransport($fakeimportrecord);
        try {
            $TRANSPORTER->extract_file();
            PluginImportLeap::validate_transported_data($TRANSPORTER);
        } catch (Exception $e) {
            $form->set_error('leap2afile', $e->getMessage());
        }
    } else {
        if (!$form->get_error('firstname') && !preg_match('/\\S/', $firstname)) {
            $form->set_error('firstname', $form->i18n('rule', 'required', 'required'));
        }
        if (!$form->get_error('lastname') && !preg_match('/\\S/', $lastname)) {
            $form->set_error('lastname', $form->i18n('rule', 'required', 'required'));
        }
        if (!$form->get_error('email')) {
            require_once 'phpmailer/class.phpmailer.php';
            if (!$form->get_error('email') && !PHPMailer::ValidateAddress($email)) {
                $form->set_error('email', get_string('invalidemailaddress', 'artefact.internal'));
            }
            if (record_exists('usr', 'email', $email) || record_exists('artefact_internal_profile_email', 'email', $email)) {
                $form->set_error('email', get_string('emailalreadytaken', 'auth.internal'));
            }
        }
    }
}
Beispiel #14
0
 /**
  * Creates a cpd or activity from the given entry
  *
  * @param SimpleXMLElement $entry    The entry to create the cpd or activity from
  * @param PluginImportLeap $importer The importer
  * @return array A list of artefact IDs created, to be used with the artefact mapping.
  */
 private static function create_cpd(SimpleXMLElement $entry, PluginImportLeap $importer)
 {
     // First decide if it's going to be a cpd or a activity depending
     // on whether it has any ancestral cpds.
     if (self::get_ancestor_entryid($entry, $importer)) {
         $artefact = new ArtefactTypeActivity();
     } else {
         $artefact = new ArtefactTypeCPD();
     }
     $artefact->set('title', (string) $entry->title);
     $artefact->set('description', PluginImportLeap::get_entry_content($entry, $importer));
     $artefact->set('owner', $importer->get('usr'));
     if (isset($entry->author->name) && strlen($entry->author->name)) {
         $artefact->set('authorname', $entry->author->name);
     } else {
         $artefact->set('author', $importer->get('usr'));
     }
     if ($published = strtotime((string) $entry->published)) {
         $artefact->set('ctime', $published);
     }
     if ($updated = strtotime((string) $entry->updated)) {
         $artefact->set('mtime', $updated);
     }
     $artefact->set('tags', PluginImportLeap::get_entry_tags($entry));
     // Set startdate and hours status if we can find them
     if ($artefact instanceof ArtefactTypeActivity) {
         $namespaces = $importer->get_namespaces();
         $ns = $importer->get_leap2a_namespace();
         $startdate = $enddate = null;
         $dates = PluginImportLeap::get_leap_dates($entry, $namespaces, $ns);
         if (!empty($dates['start']['value'])) {
             $startdate = strtotime($dates['start']['value']);
         }
         if (!empty($dates['end']['value'])) {
             $enddate = strtotime($dates['end']['value']);
         }
         $artefact->set('startdate', empty($startdate) ? $artefact->get('mtime') : $startdate);
         $artefact->set('enddate', $enddate);
         $location = $entry->xpath($namespaces[$ns] . ':spatial');
         if (is_array($location) && count($location) == 1) {
             $artefact->set('location', $location[0]);
         }
         $hours = $entry->xpath($namespaces[PluginImportLeap::NS_MAHARA] . ':hours');
         if (is_array($hours) && count($hours) == 1) {
             $artefact->set('hours', $hours[0]);
         }
     }
     $artefact->commit();
     return array($artefact->get('id'));
 }
Beispiel #15
0
function adduser_validate(Pieform $form, $values)
{
    global $USER, $TRANSPORTER;
    $authobj = AuthFactory::create($values['authinstance']);
    $institution = $authobj->institution;
    // Institutional admins can only set their own institutions' authinstances
    if (!$USER->get('admin') && !$USER->is_institutional_admin($authobj->institution)) {
        $form->set_error('authinstance', get_string('notadminforinstitution', 'admin'));
        return;
    }
    $institution = new Institution($authobj->institution);
    // Don't exceed max user accounts for the institution
    if ($institution->isFull()) {
        $institution->send_admin_institution_is_full_message();
        $form->set_error('authinstance', get_string('institutionmaxusersexceeded', 'admin'));
        return;
    }
    $username = $values['username'];
    $firstname = sanitize_firstname($values['firstname']);
    $lastname = sanitize_lastname($values['lastname']);
    $email = sanitize_email($values['email']);
    $password = $values['password'];
    if ($USER->get('admin') || get_config_plugin('artefact', 'file', 'institutionaloverride')) {
        $maxquotaenabled = get_config_plugin('artefact', 'file', 'maxquotaenabled');
        $maxquota = get_config_plugin('artefact', 'file', 'maxquota');
        if ($maxquotaenabled && $values['quota'] > $maxquota) {
            $form->set_error('quota', get_string('maxquotaexceededform', 'artefact.file', display_size($maxquota)));
        }
    }
    if (method_exists($authobj, 'is_username_valid_admin')) {
        if (!$authobj->is_username_valid_admin($username)) {
            $form->set_error('username', get_string('usernameinvalidadminform', 'auth.internal'));
        }
    } else {
        if (method_exists($authobj, 'is_username_valid')) {
            if (!$authobj->is_username_valid($username)) {
                $form->set_error('username', get_string('usernameinvalidform', 'auth.internal'));
            }
        }
    }
    if (!$form->get_error('username') && record_exists_select('usr', 'LOWER(username) = ?', array(strtolower($username)))) {
        $form->set_error('username', get_string('usernamealreadytaken', 'auth.internal'));
    }
    if (method_exists($authobj, 'is_password_valid') && !$authobj->is_password_valid($password)) {
        $form->set_error('password', get_string('passwordinvalidform', 'auth.' . $authobj->type));
    }
    if (isset($_POST['createmethod']) && $_POST['createmethod'] == 'leap2a') {
        $form->set_error('firstname', null);
        $form->set_error('lastname', null);
        $form->set_error('email', null);
        if (!$values['leap2afile'] && ($_FILES['leap2afile']['error'] == UPLOAD_ERR_INI_SIZE || $_FILES['leap2afile']['error'] == UPLOAD_ERR_FORM_SIZE)) {
            $form->reply(PIEFORM_ERR, array('message' => get_string('uploadedfiletoobig'), 'goto' => '/admin/users/add.php'));
            $form->set_error('leap2afile', get_string('uploadedfiletoobig'));
            return;
        } else {
            if (!$values['leap2afile']) {
                $form->set_error('leap2afile', $form->i18n('rule', 'required', 'required'));
                return;
            }
        }
        if ($values['leap2afile']['type'] == 'application/octet-stream') {
            require_once 'file.php';
            $mimetype = file_mime_type($values['leap2afile']['tmp_name']);
        } else {
            $mimetype = trim($values['leap2afile']['type'], '"');
        }
        $date = time();
        $niceuser = preg_replace('/[^a-zA-Z0-9_-]/', '-', $values['username']);
        safe_require('import', 'leap');
        $fakeimportrecord = (object) array('data' => array('importfile' => $values['leap2afile']['tmp_name'], 'importfilename' => $values['leap2afile']['name'], 'importid' => $niceuser . '-' . $date, 'mimetype' => $mimetype));
        $TRANSPORTER = new LocalImporterTransport($fakeimportrecord);
        try {
            $TRANSPORTER->extract_file();
            PluginImportLeap::validate_transported_data($TRANSPORTER);
        } catch (Exception $e) {
            $form->set_error('leap2afile', $e->getMessage());
        }
    } else {
        if (!$form->get_error('firstname') && empty($firstname)) {
            $form->set_error('firstname', $form->i18n('rule', 'required', 'required'));
        }
        if (!$form->get_error('lastname') && empty($lastname)) {
            $form->set_error('lastname', $form->i18n('rule', 'required', 'required'));
        }
        if (!$form->get_error('email')) {
            if (!$form->get_error('email') && empty($email)) {
                $form->set_error('email', get_string('invalidemailaddress', 'artefact.internal'));
            }
            if (record_exists('usr', 'email', $email) || record_exists('artefact_internal_profile_email', 'email', $email)) {
                $form->set_error('email', get_string('emailalreadytaken', 'auth.internal'));
            }
        }
    }
}
Beispiel #16
0
 /**
  * Returns if the entry has the given term in the given category
  *
  * @param SimpleXMLElement $entry    The entry to check
  * $param PluginImportLeap $importer The importer
  * @param string $category           The category to look in. See http://wiki.cetis.ac.uk/2009-03/Leap2A_categories
  * @param string $term               The term to look for (see the docs for the appropriate category)
  * @return boolean Whether the entry has the term in the category
  */
 public static function is_correct_category_scheme(SimpleXMLElement $entry, PluginImportLeap $importer, $category, $term)
 {
     $result = $entry->xpath('a:category[(' . $importer->curie_xpath('@scheme', $importer->get_categories_namespace(), $category . '#') . ') and @term="' . $term . '"]');
     return isset($result[0]) && $result[0] instanceof SimpleXMLElement;
 }
Beispiel #17
0
function import_validate(Pieform $form, $values)
{
    global $USER, $TRANSPORTER;
    if (!isset($values['leap2afile'])) {
        $form->set_error('leap2afile', $form->i18n('rule', 'required', 'required'));
        return;
    }
    if ($values['leap2afile']['type'] == 'application/octet-stream') {
        require_once 'file.php';
        $mimetype = file_mime_type($values['leap2afile']['tmp_name']);
    } else {
        $mimetype = trim($values['leap2afile']['type'], '"');
    }
    $date = time();
    $niceuser = preg_replace('/[^a-zA-Z0-9_-]/', '-', $USER->get('username'));
    safe_require('import', 'leap');
    $fakeimportrecord = (object) array('data' => array('importfile' => $values['leap2afile']['tmp_name'], 'importfilename' => $values['leap2afile']['name'], 'importid' => $niceuser . '-' . $date, 'mimetype' => $mimetype));
    $TRANSPORTER = new LocalImporterTransport($fakeimportrecord);
    try {
        $TRANSPORTER->extract_file();
        PluginImportLeap::validate_transported_data($TRANSPORTER);
    } catch (Exception $e) {
        $form->set_error('leap2afile', $e->getMessage());
        $TRANSPORTER->cleanup();
    }
    // Check if import data may exceed the user's file quota
    $importdata = $TRANSPORTER->files_info();
    require_once 'function.dirsize.php';
    $importdatasize = dirsize($importdata['tempdir'] . 'extract/files');
    if ($USER->get('quotaused') + $importdatasize > $USER->get('quota')) {
        $form->set_error('leap2afile', get_string('importexceedquota', 'import'));
        $TRANSPORTER->cleanup();
    }
}
Beispiel #18
0
 /**
  * Render import entry requests for Mahara milestones and their facts
  * @param PluginImportLeap $importer
  * @return HTML code for displaying milestones and choosing how to import them
  */
 public static function render_import_entry_requests(PluginImportLeap $importer)
 {
     $importid = $importer->get('importertransport')->get('importid');
     // Get import entry requests for Mahara milestones
     $entrymilestones = array();
     if ($iermilestones = get_records_select_array('import_entry_requests', 'importid = ? AND entrytype = ?', array($importid, 'milestone'))) {
         foreach ($iermilestones as $iermilestone) {
             $milestone = unserialize($iermilestone->entrycontent);
             $milestone['id'] = $iermilestone->id;
             $milestone['decision'] = $iermilestone->decision;
             if (is_string($iermilestone->duplicateditemids)) {
                 $iermilestone->duplicateditemids = unserialize($iermilestone->duplicateditemids);
             }
             if (is_string($iermilestone->existingitemids)) {
                 $iermilestone->existingitemids = unserialize($iermilestone->existingitemids);
             }
             $milestone['disabled'][PluginImport::DECISION_IGNORE] = false;
             $milestone['disabled'][PluginImport::DECISION_ADDNEW] = false;
             $milestone['disabled'][PluginImport::DECISION_APPEND] = true;
             $milestone['disabled'][PluginImport::DECISION_REPLACE] = true;
             if (!empty($iermilestone->duplicateditemids)) {
                 $duplicated_item = artefact_instance_from_id($iermilestone->duplicateditemids[0]);
                 $milestone['duplicateditem']['id'] = $duplicated_item->get('id');
                 $milestone['duplicateditem']['title'] = $duplicated_item->get('title');
                 $res = $duplicated_item->render_self(array());
                 $milestone['duplicateditem']['html'] = $res['html'];
             } else {
                 if (!empty($iermilestone->existingitemids)) {
                     foreach ($iermilestone->existingitemids as $id) {
                         $existing_item = artefact_instance_from_id($id);
                         $res = $existing_item->render_self(array());
                         $milestone['existingitems'][] = array('id' => $existing_item->get('id'), 'title' => $existing_item->get('title'), 'html' => $res['html']);
                     }
                 }
             }
             // Get import entry requests of facts in the milestone
             $entryfacts = array();
             if ($ierfacts = get_records_select_array('import_entry_requests', 'importid = ? AND entrytype = ? AND entryparent = ?', array($importid, 'fact', $iermilestone->entryid))) {
                 foreach ($ierfacts as $ierfact) {
                     $fact = unserialize($ierfact->entrycontent);
                     $fact['id'] = $ierfact->id;
                     $fact['decision'] = $ierfact->decision;
                     $fact['completiondate'] = format_date($fact['completiondate'], 'strftimedate');
                     $fact['disabled'][PluginImport::DECISION_IGNORE] = false;
                     $fact['disabled'][PluginImport::DECISION_ADDNEW] = false;
                     $fact['disabled'][PluginImport::DECISION_APPEND] = true;
                     $fact['disabled'][PluginImport::DECISION_REPLACE] = true;
                     $entryfacts[] = $fact;
                 }
             }
             $milestone['entryfacts'] = $entryfacts;
             $entrymilestones[] = $milestone;
         }
     }
     $smarty = smarty_core();
     $smarty->assign_by_ref('displaydecisions', $importer->get('displaydecisions'));
     $smarty->assign_by_ref('entrymilestones', $entrymilestones);
     return $smarty->fetch('artefact:milestones:import/milestones.tpl');
 }