00001 <?php
00002
00011 class TKSnapInteractivateInstructorEditor extends TKSnapEditor {
00012 private $description = '';
00013 private $placements = array();
00014 private $preparations = array();
00015
00023 private function grabResponse() {
00024 $json = json_decode(utf8_encode($_REQUEST['result']));
00025
00026 $this->description = $json->description;
00027 $this->placements = $json->placements;
00028 $this->preparations = $json->preparations;
00029
00030 return true;
00031 }
00032
00042 protected function showEditor($cm, $failed) {
00043 if($failed) {
00044 $this->grabResponse();
00045 }
00046 else {
00047 $this->description = $cm->getDescription();
00048 $this->placements = $cm->getPlacements();
00049 $this->preparations = $cm->getPreparations();
00050 }
00051
00052 $json = array(
00053 'description' => $this->description,
00054 'placements' => $this->placements,
00055 'preparations' => $this->preparations
00056 );
00057
00058 $json = htmlspecialchars(json_encode($json), ENT_NOQUOTES);
00059
00060 $js = <<<END_JAVASCRIPT
00061 SWAT.use('InteractivateInstructorEditor');
00062
00070 function initializeEditor() {
00071 var instructor = new Instructor();
00072 instructor.unserialize($json);
00073 var editor = new InstructorEditor(instructor);
00074 $('editorContainer').insert(editor);
00075 }
00076
00077 END_JAVASCRIPT;
00078
00079 global $prm;
00080 $prm->setOption('prototype', true);
00081 $prm->setOption('swatjs', true);
00082 $prm->loadJS($js);
00083 $prm->loadJS('initializeEditor()', 'OnLoad');
00084
00085 $this->addText('<div id="editorContainer"></div>');
00086 }
00087
00096 protected function processSave($oldCM) {
00097 if(!$this->grabResponse())
00098 return false;
00099
00100 $cmNew = new SnapContentInteractivateInstructor($this->version);
00101
00102 $cmNew->setDescription($this->description);
00103 $cmNew->clearPlacements();
00104 foreach($this->placements as $plc)
00105 $cmNew->addPlacement($plc);
00106 $cmNew->clearPreparations();
00107 foreach($this->preparations as $prep)
00108 $cmNew->addPreparation($prep);
00109
00110
00111 if(count($cmNew->getLoadErrors()) > 0) {
00112 $this->addText('<p><b>Could not save because of the following errors</b>: <ul><li>'
00113 . implode($cmNew->getLoadErrors(), '</li><li>') . '</li></ul></p>');
00114 return false;
00115 }
00116
00117
00118 $cmNew->getXML();
00119
00120
00121 if(count($cmNew->getError()) > 0) {
00122 $this->addText('<p><b>Fatal Error</b>: Could not save document: <ul><li>' . implode($cmNew->getError(), '</li><li>')
00123 . '</li></ul></p>');
00124 return false;
00125 }
00126
00127 return $cmNew;
00128 }
00129 }
00130
00131 ?>