00001 <?php
00002
00011 class TKSnapLessonPlanEditor extends TKSnapEditor {
00021 protected function showEditor($cm, $failed) {
00022 if($failed) {
00023 $stdsAddressed = array();
00024 $i = 0;
00025 while(isset($_REQUEST['standards_box_' . $i])) {
00026 $stdsAddressed[] = $_REQUEST['standards_box_' . $i];
00027 $i++;
00028 }
00029 $standardsNumber = $i;
00030
00031 $objs = array();
00032 $i = 0;
00033 while(isset($_REQUEST['objectives_box_' . $i])) {
00034 $objs[] = $_REQUEST['objectives_box_' . $i];
00035 $i++;
00036 }
00037 $objectivesNumber = $i;
00038
00039 $mats = array();
00040 $i = 0;
00041 while(isset($_REQUEST['materials_box_' . $i])) {
00042 $mats[] = $_REQUEST['materials_box_' . $i];
00043 $i++;
00044 }
00045 $materialsNumber = $i;
00046
00047 $meds = array();
00048 $i = 0;
00049 while(isset($_REQUEST['media_box_' . $i])) {
00050 $meds[] = $_REQUEST['media_box_' . $i];
00051 $i++;
00052 }
00053 $mediaNumber = $i;
00054
00055 $eqs = array();
00056 $i = 0;
00057 while(isset($_REQUEST['equipment_box_' . $i])) {
00058 $eqs[] = $_REQUEST['equipment_box_' . $i];
00059 $i++;
00060 }
00061 $equipmentNumber = $i;
00062
00063 $kts = array();
00064 $i = 0;
00065 while(isset($_REQUEST['keyterms_box_' . $i])) {
00066 $kts[] = $_REQUEST['keyterms_box_' . $i];
00067 $i++;
00068 }
00069 $keytermsNumber = $i;
00070 }
00071 else {
00072 $stdsAddressed = $cm->getStandardsAddressed();
00073 $objs = $cm->getObjectives();
00074 $mats = $cm->getRequiredMaterials();
00075 $meds = $cm->getMediaUsed();
00076 $eqs = $cm->getRequiredEquipment();
00077 $kts = $cm->getKeyTerms();
00078
00079 $standardsNumber = count($cm->getStandardsAddressed());
00080 $objectivesNumber = count($cm->getObjectives());
00081 $materialsNumber = count($cm->getRequiredMaterials());
00082 $mediaNumber = count($cm->getMediaUsed());
00083 $equipmentNumber = count($cm->getRequiredEquipment());
00084 $keytermsNumber = count($cm->getKeyTerms());
00085 }
00086 $javascript = <<<END_JAVASCRIPT
00087 var counters = new Array();
00088 counters['standards'] = '$standardsNumber';
00089 counters['objectives'] = '$objectivesNumber';
00090 counters['materials'] = '$materialsNumber';
00091 counters['media'] = '$mediaNumber';
00092 counters['equipment'] = '$equipmentNumber';
00093 counters['keyterms'] = '$keytermsNumber';
00094
00095 function createBox(where, name, addButton, whichCounter) {
00096 var br = document.createElement('br');
00097 var myElt = document.createElement('span');
00098 myElt.innerHTML = '<input type="text" name="' + name + counters[whichCounter] + '" id="' + name + counters[whichCounter] + '" /> <br />';
00099 where.insertBefore(myElt, addButton);
00100 var nameOfElt = name + counters[whichCounter];
00101 var box = document.getElementById(nameOfElt);
00102 box.focus();
00103 counters[whichCounter]++;
00104 }
00105
00106 END_JAVASCRIPT;
00107
00108 global $prm;
00109 $prm->setOption('prototype', true);
00110 $prm->includeJS('LessonPlan.js', 'DefaultSkin');
00111 $prm->load($javascript, array('inFormat' => 'html', 'trans_target' => 'ExtraJS'));
00112
00113 $prototypes = '';
00114 foreach(SnapContentLessonPlan::$PROTOTYPES as $sname => $proto) {
00115 $required = ($proto['required'] ? 'true' : 'false');
00116 $note = ($proto['note'] ? 'true' : 'false');
00117 $prototypes .= " LessonPlanInfo.addPrototype('$sname', '$proto[name]', $required, $note);\n";
00118 }
00119
00120 $outlines = '';
00121 foreach(SnapContentLessonPlan::$OUTLINES as $name => $protos) {
00122 if($name == 'Custom')
00123 continue;
00124 $protoStr = "[ '" . implode("','", $protos) . "' ]";
00125 $outlines .= " LessonPlanInfo.addOutline('$name', $protoStr);\n";
00126 }
00127
00128 $outlineType = $cm->getOutlineType();
00129
00130 $initStr = '';
00131 $initStr2 = '';
00132 if(isset($_REQUEST['out'])) {
00133 $xml = simplexml_load_string($_REQUEST['out']);
00134 foreach($xml->event as $event) {
00135 $time = (string)$event->time;
00136 $content = (string)$event->content;
00137 if($event->proto->custom == '0') {
00138 $sname = addslashes((string)$event->proto->sname);
00139 $initStr .= " LessonPlanInfo.setEvent('$sname', '$time', '$content');\n";
00140 if($outlineType == 'Custom')
00141 $initStr .= " LessonPlanInfo.addCustomEvent('$sname', '$time', '$content');\n";
00142 }
00143 else {
00144 $required = ((string)$event->proto->required == '1' ? 'true' : 'false');
00145 $note = ((string)$event->proto->note == '1' ? 'true' : 'false');
00146 $name = addslashes((string)$event->proto->name);
00147 if($outlineType == 'Custom')
00148 $initStr .= " LessonPlanInfo.addCustomEvent({ name: '$name', required: $required, note: $note }, '$time', '$content');\n";
00149
00150 }
00151 }
00152 }
00153 else {
00154 $fields = $cm->getOutlineFields();
00155 if(is_array($fields)) {
00156 foreach($fields as $field) {
00157 $time = base64_encode($field['time']);
00158 $content = base64_encode($field['content']);
00159 $proto = $field['proto'];
00160 if(is_string($proto)) {
00161 $proto = addslashes($proto);
00162 $initStr .= " LessonPlanInfo.setEvent('$proto', '$time', '$content');\n";
00163 if($outlineType == 'Custom')
00164 $initStr .= " LessonPlanInfo.addCustomEvent('$proto', '$time', '$content');\n";
00165 }
00166 else {
00167 $required = ($proto['required'] ? 'true' : 'false');
00168 $note = ($proto['note'] ? 'true' : 'false');
00169 $name = addslashes($proto['name']);
00170 if($outlineType == 'Custom')
00171 $initStr .= " LessonPlanInfo.addCustomEvent({ name: '$name', required: $required, note: $note }, '$time', '$content');\n";
00172 }
00173 }
00174 }
00175 }
00176
00177 $form = new TKForm();
00178 $form->setId('editorForm');
00179 $form->onsubmit = 'return window.lpo.onSubmit()';
00180 $table = $form->addTable();
00181 $table->addText("Title of Lesson:", array('class' => array('snapInfoLabel')));
00182 $fi = $table->addFormInput('text', 'lessonTitle', $this->fixEntities($failed ? $_REQUEST['lessonTitle'] :
00183 $cm->getLessonTitle()));
00184 $checkBlanks[$fi->getId()] = 'Title of Lesson';
00185
00186
00187 $rightBox = $table->addNullBox(array('rowspan' => 11, 'valign' => 'top'));
00188 $rightBox->addText('<h2>Presentation Outline</h2>');
00189 $rightBox->addText('<div id="outlineContainer"></div>');
00190
00191
00192
00193 $table->addRow();
00194 $table->addText("Grade level:", array('class' => array('snapInfoLabel')));
00195 $fi = $table->addFormInput('text', 'gradeLevel', $this->fixEntities($failed ? $_REQUEST['gradeLevel'] :
00196 $cm->getGradeLevel()));
00197 $checkBlanks[$fi->getId()] = 'Grade Level';
00198
00199 $table->addRow();
00200 $table->addText("Lesson Abstract:", array('class' => array('snapInfoLabel')));
00201 $fi = $table->addTextArea('lessonAbstract', $this->fixEntities($failed ? $_REQUEST['lessonAbstract'] :
00202 $cm->getLessonAbstract()), 7, 30);
00203 $checkBlanks[$fi->getId()] = 'Lesson Abstract';
00204
00205 $table->addRow();
00206 $table->addText("Standards Addressed:", array('class' => array( 'snapInfoLabel')));
00207 $standardsBox = $table->addNullBox();
00208 $standardsBox->class = array(' ');
00209
00210 if(is_array($stdsAddressed))
00211 foreach($stdsAddressed as $count => $thisStandard) {
00212 $standardsBox->addFormInput('text', 'standards_box_' . $count, $thisStandard);
00213 $standardsBox->addText('<br />');
00214 }
00215
00216 $addButton = $standardsBox->addButton('Add Standard');
00217 $buttonID = $addButton->getId();
00218 $standardsID = $standardsBox->getId();
00219 $js = <<<END_JAVASCRIPT
00220 var standards = document.getElementById('$standardsID');
00221 createBox(standards, 'standards_box_', document.getElementById('$buttonID'), 'standards');
00222 return false;
00223 END_JAVASCRIPT;
00224 $addButton->setAction('onclick', $js);
00225
00226 $table->addRow();
00227 $table->addText("Objectives:", array('class' => array('snapInfoLabel')));
00228 $objectivesBox = $table->addNullBox();
00229 $objectivesBox->class = array(' ');
00230
00231 if(is_array($objs))
00232 foreach($objs as $count => $thisObjective) {
00233 $objectivesBox->addFormInput('text', 'objectives_box_' . $count, $thisObjective);
00234 $objectivesBox->addText('<br />');
00235 }
00236
00237 $addButton = $objectivesBox->addButton('Add Objective');
00238 $buttonID = $addButton->getId();
00239 $objectivesID = $objectivesBox->getId();
00240 $js = <<<END_JAVASCRIPT
00241 var objectives = document.getElementById('$objectivesID');
00242
00243 createBox(objectives, 'objectives_box_', document.getElementById('$buttonID'), 'objectives');
00244 return false;
00245 END_JAVASCRIPT;
00246 $addButton->setAction('onclick', $js);
00247
00248 $table->addRow();
00249 $table->addText("Key Terms:", array('class' => array('snapInfoLabel')));
00250 $keytermsBox = $table->addNullBox();
00251 $keytermsBox->class = array(' ');
00252
00253 if(is_array($kts))
00254 foreach($kts as $count => $thisKeyterm) {
00255 $keytermsBox->addFormInput('text', 'keyterms_box_' . $count, $thisKeyterm);
00256 $keytermsBox->addText('<br />');
00257 }
00258
00259 $addButton = $keytermsBox->addButton('Add Key Term');
00260 $buttonID = $addButton->getId();
00261 $keytermsID = $keytermsBox->getId();
00262 $js = <<<END_JAVASCRIPT
00263 var keyterms = document.getElementById('$keytermsID');
00264
00265 createBox(keyterms, 'keyterms_box_', document.getElementById('$buttonID'), 'keyterms');
00266 return false;
00267 END_JAVASCRIPT;
00268 $addButton->setAction('onclick', $js);
00269
00270 $table->addRow();
00271 $table->addText("Prerequisite Knowledge:", array('class' => array('snapInfoLabel')));
00272 $fi = $table->addTextArea('prereqs', $this->fixEntities($failed ? $_REQUEST['prereqs'] : $cm->getPrereqs()), 7, 30);
00273 $checkBlanks[$fi->getId()] = 'Prerequisite Knowledge';
00274
00275 $table->addRow();
00276 $table->addText("Teacher Preparation:", array('class'=>array('snapInfoLabel')));
00277 $fi = $table->addTextArea('teacherPrep', $this->fixEntities($failed ? $_REQUEST['teacherPrep']
00278 : $cm->getTeacherPrep()), 7, 30);
00279 $checkBlanks[$fi->getId()] = 'Teacher Preparation';
00280
00281 $table->addRow();
00282 $table->addText('Required Materials:', array('class'=>array('snapInfoLabel')));
00283
00284 $materialsBox = $table->addNullBox();
00285 $materialsBox->class = array(' ');
00286
00287 if(is_array($mats))
00288 foreach($mats as $count => $thisMaterial) {
00289 $materialsBox->addFormInput('text', 'materials_box_' . $count, $thisMaterial);
00290 $materialsBox->addText('<br />');
00291 }
00292
00293 $addButton = $materialsBox->addButton('Add Material');
00294 $buttonID = $addButton->getId();
00295 $materialsID = $materialsBox->getId();
00296 $js = <<<END_JAVASCRIPT
00297 var materials = document.getElementById('$materialsID');
00298 createBox(materials, 'materials_box_', document.getElementById('$buttonID'), 'materials');
00299 return false;
00300 END_JAVASCRIPT;
00301 $addButton->setAction('onclick', $js);
00302
00303 $table->addRow();
00304
00305 $table->addText('Media Used:', array('class'=>array('snapInfoLabel')));
00306 $mediaBox = $table->addNullBox();
00307 $mediaBox->class = array(' ');
00308
00309 if(is_array($meds))
00310 foreach($meds as $count => $thisMedia) {
00311 $mediaBox->addFormInput('text', 'media_box_' . $count, htmlspecialchars($thisMedia));
00312 $mediaBox->addText('<br />');
00313 }
00314
00315 $addButton = $mediaBox->addButton('Add Media');
00316 $buttonID = $addButton->getId();
00317 $mediaID = $mediaBox->getId();
00318 $js = <<<END_JAVASCRIPT
00319 var media = document.getElementById('$mediaID');
00320 createBox(media, 'media_box_', document.getElementById('$buttonID'), 'media');
00321 return false;
00322 END_JAVASCRIPT;
00323 $addButton->setAction('onclick', $js);
00324
00325 $table->addRow();
00326
00327 $table->addText('Required Equipment:', array('class'=>array('snapInfoLabel')));
00328 $equipmentBox = $table->addNullBox();
00329 $equipmentBox->class = array(' ');
00330
00331 if(is_array($eqs))
00332 foreach($eqs as $count => $thisEquipment) {
00333 $equipmentBox->addFormInput('text', 'equipment_box_' . $count, $thisEquipment);
00334 $equipmentBox->addText('<br />');
00335 }
00336
00337 $addButton = $equipmentBox->addButton('Add Equipment');
00338 $buttonID = $addButton->getId();
00339 $equipmentID = $equipmentBox->getId();
00340 $js = <<<END_JAVASCRIPT
00341 var equipment = document.getElementById('$equipmentID');
00342 createBox(equipment, 'equipment_box_', document.getElementById('$buttonID'), 'equipment');
00343 return false;
00344 END_JAVASCRIPT;
00345 $addButton->setAction('onclick', $js);
00346
00347 $table->addRow();
00348 $table->addText('Safety Reminders:', array('class' => array('snapInfoLabel')));
00349 $fi = $table->addTextArea('safety', $this->fixEntities($failed ? $_REQUEST['safety'] : $cm->getSafety()), 7, 30);
00350 $checkBlanks[$fi->getId()] = 'Safety Reminders';
00351
00352 $out = "LessonPlanInfo.setCheckBlankFields({";
00353 foreach($checkBlanks as $cbId => $fldName)
00354 $out .= "$cbId: '$fldName',";
00355 $out = rtrim($out, ',') . '})';
00356 $prm->loadJS(<<<END_JAVASCRIPT
00357
00358 function initLessonPlan() {
00359 $prototypes
00360 $outlines
00361 $initStr
00362 $out
00363 LessonPlanInfo.setDefaultOutline('$outlineType');
00364 window.lpo = new LessonPlanOutline($('outlineContainer'));
00365 $initStr2
00366 }
00367
00368 END_JAVASCRIPT
00369 );
00370 $prm->load('initLessonPlan()', array('inFormat' => 'html', 'trans_target' => 'OnLoad'));
00371
00372 $table->addRow();
00373 $hb = $table->addHBox(array('colspan' => 3));
00374 $hb->setId('saveBox');
00375
00376 $hb->addButton('Save')->setId('snap2ed_save')->setType('button')->onclick = 'window.lpo.doSubmit(false, true)';
00377 $hb->addButton('Save and Exit')->setId('snap2ed_saveAndExit')->setType('button')->onclick = 'window.lpo.doSubmit(true, true)';
00378 $hb->addButton('Exit without Saving')->setId('snap2ed_exit')->setType('button')->onclick = 'window.lpo.doSubmit(true, false)';
00379
00380 $this->add($form);
00381 }
00382
00391 private function fixEntities($str) {
00392 $str = preg_replace('/&(.*?);/', '&$1;', $str);
00393 return $str;
00394 }
00395
00404 protected function processSave($oldCM) {
00405 $lessonTitle = $_REQUEST['lessonTitle'];
00406 $gradeLevel = $_REQUEST['gradeLevel'];
00407 $lessonAbstract = $_REQUEST['lessonAbstract'];
00408 $prereqs = $_REQUEST['prereqs'];
00409 $teacherPrep = $_REQUEST['teacherPrep'];
00410 $safety = $_REQUEST['safety'];
00411 $boxNames = array('standards', 'objectives', 'materials', 'media', 'equipment', 'keyterms');
00412 $boxes = array();
00413 foreach($boxNames as $boxName) {
00414 $i = 0;
00415 while(isset($_REQUEST[$boxName . '_box_' . $i])) {
00416 if($_REQUEST[$boxName . '_box_' . $i] != '')
00417 $boxes[$boxName][] = $_REQUEST[$boxName . '_box_' . $i];
00418 $i++;
00419
00420 }
00421 if(!isset($boxes[$boxName]))
00422 $boxes[$boxName] = array();
00423 }
00424
00425 $whichOutline = $_REQUEST['whichOutline'];
00426 if ($whichOutline == '0') {
00427 $error = "Please select a lesson outline type.";
00428 $html = "<p><b>Error:</b> Could not save document:</p><ul><li>$error</li></ul>";
00429 $this->addText($html);
00430 return false;
00431 }
00432
00433 $out = $_REQUEST['out'];
00434 $outXml = simplexml_load_string($out);
00435
00436 $fields = array();
00437 $error = array();
00438 foreach($outXml->event as $event) {
00439 $proto = $event->proto;
00440 if($proto->custom == 0)
00441 $proto = (string)$proto->sname;
00442 else {
00443 $tmp = array(
00444 'name' => (string)$proto->name,
00445 'required' => (string)$proto->required == '1' ? true : false,
00446 'note' => (string)$proto->note == '1' ? true : false
00447 );
00448 $proto = $tmp;
00449 }
00450 $time = base64_decode((string)$event->time);
00451 $content = base64_decode((string)$event->content);
00452 if(is_string($proto))
00453 $required = SnapContentLessonPlan::$PROTOTYPES[$proto]['required'];
00454 else
00455 $required = $proto['required'];
00456 if($required && preg_match('/^\s*$/', $content))
00457 {
00458 $error[] = 'Field <b>' . (is_string($proto) ? SnapContentLessonPlan::$PROTOTYPES[$proto]['name'] : $proto['name'])
00459 . '</b> is required!';
00460 }
00461 $fields[] = array($proto, $time, $content);
00462 }
00463
00464 if(count($error) > 0) {
00465 $html = '<p><b>Error:</b> Could not save document:</p><ul><li>' . implode($error) . '</li></ul>';
00466 $this->addText($html);
00467 return false;
00468 }
00469
00470 $content = array(
00471 'lessonTitle' => $lessonTitle,
00472 'gradeLevel' => $gradeLevel,
00473 'lessonAbstract' => $lessonAbstract,
00474 'standardsAddressed' => $boxes['standards'],
00475 'objectives' => $boxes['objectives'],
00476 'prereqs' => $prereqs,
00477 'teacherPrep' => $teacherPrep,
00478 'requiredMaterials'=>$boxes['materials'],
00479 'mediaUsed' => $boxes['media'],
00480 'requiredEquipment' => $boxes['equipment'],
00481 'safety' => $safety,
00482 'keyterms' => $boxes['keyterms']
00483 );
00484
00485 $ret = true;
00486
00487 $cmNew = new SnapContentLessonPlan($this->version);
00488 if(!$cmNew->setStandardFields($content))
00489 $ret = false;
00490
00491 if(!$cmNew->setOutlineType($whichOutline))
00492 $ret = false;
00493
00494 foreach($fields as $field) {
00495 if(!$cmNew->setOutlineField($field[0], $field[1], $field[2]))
00496 $ret = false;
00497 }
00498
00499 if(!$ret) {
00500 $error = $cmNew->getErrors();
00501 $html = "<p><b>Error:</b> Could not save document:</p><ul><li>" . implode( "</li><li>", $error)
00502 . "</li></ul>";
00503 $this->addText($html);
00504 return false;
00505 }
00506
00507 return $cmNew;
00508 }
00509 }
00510
00511 ?>