00001 <?php
00002
00011 class TKSnapMediaAgentsheetsEditor extends TKSnapEditor {
00021 protected function showEditor($cm, $failed) {
00022 $form = new TKForm();
00023 $table = $form->addTable();
00024 $table->addTextTo('header', 'Upload Applet', array('colspan' => 2, 'style' => array('font-size' => '1.4em')));
00025
00026 $table->addText("Applet Directory (.zip)", array('class' => array('snapInfoLabel')));
00027 $upload = $table->addFormInput('file', 'fileUpload');
00028 $table->addRow();
00029 $table->addText("Index file (.html)", array('class'=>array('snapInfoLabel')));
00030 $indexFileUpload = $table->addFormInput('file', 'indexFile');
00031
00032
00033
00034
00035
00036 $upload->size = 40;
00037 $indexFileUpload->size = 40;
00038 $form->addText("<br />\n");
00039 $form->addFormInput('submit', 'snap2ed_save', "Save");
00040 $form->addFormInput('submit', 'snap2ed_saveAndExit', "Save and Exit");
00041 $form->addFormInput('submit', 'snap2ed_exit', "Exit without Saving");
00042 $this->add($form);
00043 }
00044
00054 protected function getValue($pattern, $indexFile) {
00055 $matches = array();
00056 preg_match($pattern, $indexFile, $matches);
00057
00058 return isset($matches[1]) ? $matches[1] : '';
00059 }
00060
00061
00070 protected function processSave($oldCM) {
00071 if($_FILES['fileUpload']['tmp_name'] != "") {
00072 $fileName = $_FILES['fileUpload']['name'];
00073 $tmpFile = $_FILES['fileUpload']['tmp_name'];
00074 }
00075 else {
00076 $tmpFile = "";
00077 }
00078 if (($_FILES['indexFile']['tmp_name']) != "" ) {
00079 $indexName = $_FILES['indexFile']['tmp_name'];
00080 $indexContents = file_get_contents($indexName);
00081
00082 $width = '/<APPLET CODEBASE="applet" CODE="__mysimulation__.class" ARCHIVE="uAgentsheets.jar" WIDTH="([0-9]*)"/';
00083 $height = '/<APPLET CODEBASE="applet" CODE="__mysimulation__.class" ARCHIVE="uAgentsheets.jar" WIDTH="[0-9]*" HEIGHT="([0-9]*)"/';
00084 $wsCols = '/<PARAM NAME="WorksheetColumns" VALUE="([0-9]*)"/';
00085 $wsRows = '/<PARAM NAME="WorksheetRows" VALUE="([0-9]*)/';
00086 $worksheet = '/<PARAM NAME="DefaultWorksheet" VALUE="(.*?)\.ws">/';
00087 $additionalWorksheets = '/<PARAM NAME="AllWorksheets" VALUE="(.*?)">/';
00088
00089 $width = $this->getValue($width, $indexContents);
00090 $height = $this->getValue($height, $indexContents);
00091 $wsCols = $this->getValue($wsCols, $indexContents);
00092 $wsRows = $this->getValue($wsRows, $indexContents);
00093 $worksheet = $this->getValue($worksheet, $indexContents) . '.ws';
00094 $additionalWorksheets = $this->getValue($additionalWorksheets, $indexContents);
00095 if($additionalWorksheets != '')
00096 $additionalWorksheets = explode(':', $additionalWorksheets);
00097 else
00098 $additionalWorksheets = array();
00099 } else {
00100 $width = $oldCM->getWidth();
00101 $height = $oldCM->getHeight();
00102 $wsCols = $oldCM->getWsCols();
00103 $wsRows= $oldCM->getWsRows();
00104 $worksheet = $oldCM->getWorksheet();
00105 $additionalWorksheets = $oldCM->getAdditionalWorksheets();
00106 }
00107
00108
00109 $cmNew = new SnapContentMediaAgentsheetsApplet($this->version);
00110 if($tmpFile == "") {
00111 $stat = true;
00112 if($width != "") $stat = $cmNew->setWidth($oldCM, $width);
00113 if($height != "" && $stat) $stat = $cmNew->setHeight($oldCM, $height);
00114 if($wsCols != "" && $stat) $stat = $cmNew->setWsCols($oldCM, $wsCols);
00115 if($wsRows != "" && $stat) $stat = $cmNew->setWsRows($oldCM, $wsRows);
00116
00117 if($worksheet != "" && $stat) $stat = $cmNew->setWorksheet($oldCM, $worksheet);
00118 if(count($additionalWorksheets) > 0 && $stat) $stat = $cmNew->setAdditionalWorksheets($oldCM, $additionalWorksheets);
00119 }
00120 else
00121 $stat = $cmNew->uploadApplet($tmpFile, $fileName, $width, $height, $wsCols, $wsRows, $worksheet, $additionalWorksheets);
00122
00123 if(!$stat) {
00124 $cmNew->delete();
00125 $html = "<p><b>Error:<b/> Could not save applet: " . $cmNew->getLastError() . "</p>";
00126 $this->addText($html);
00127 return false;
00128 }
00129 return $cmNew;
00130 }
00131 }
00132
00133 ?>