1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47:
48: class ArticleView extends AlphaView {
49: 50: 51: 52: 53: 54:
55: public function markdownView($fields=array()) {
56: global $config;
57:
58: $markdown = new MarkdownFacade($this->BO);
59:
60: $fields['markdownContent'] = $markdown->getContent();
61:
62: $this->loadTemplate($this->BO, 'markdown', $fields);
63: }
64:
65: 66: 67: 68: 69:
70: protected function after_createView_callback() {
71: echo '<p><strong>Please note</strong> that you will only be able to attach files to the article once it has been created.</p><br>';
72: }
73:
74: 75: 76: 77: 78: 79:
80: public function listView($fields=array()) {
81: $fields['dateAdded'] = $this->BO->getCreateTS()->getDate();
82: parent::listView($fields);
83: }
84:
85: 86: 87: 88: 89: 90:
91: public function editView($fields=array()) {
92: if(method_exists($this, 'before_editView_callback'))
93: $this->before_editView_callback();
94:
95: global $config;
96:
97:
98: $fields['formAction'] = $_SERVER['REQUEST_URI'];
99:
100:
101: $fields['formID'] = get_class($this->BO).'_'.$this->BO->getID();
102:
103:
104: $fields['formFields'] = $this->renderAllFields('edit');
105:
106:
107: $fieldname = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(AlphaSecurityUtils::encrypt('saveBut')) : 'saveBut');
108: $button = new Button('submit', 'Save', $fieldname);
109: $fields['saveButton'] = $button->render();
110:
111: $js = "$('#dialogDiv').text('Are you sure you wish to delete this item?');
112: $('#dialogDiv').dialog({
113: buttons: {
114: 'OK': function(event, ui) {
115: $('[id=\"".($config->get('security.encrypt.http.fieldnames') ? base64_encode(AlphaSecurityUtils::encrypt('deleteOID')) : 'deleteOID')."\"]').attr('value', '".$this->BO->getOID()."');
116: $('#deleteForm').submit();
117: },
118: 'Cancel': function(event, ui) {
119: $(this).dialog('close');
120: }
121: }
122: })
123: $('#dialogDiv').dialog('open');
124: return false;";
125: $button = new Button($js, "Delete", "deleteBut");
126: $fields['deleteButton'] = $button->render();
127:
128: $button = new Button("document.location = '".FrontController::generateSecureURL('act=ListAll&bo='.get_class($this->BO))."'", "Back to List", "cancelBut");
129: $fields['cancelButton'] = $button->render();
130:
131: $tags = array();
132:
133: if(is_object($this->BO->getPropObject('tags')))
134: $tags = $this->BO->getPropObject('tags')->getRelatedObjects();
135:
136: if(count($tags) > 0) {
137: $button = new Button("document.location = '".FrontController::generateSecureURL('act=EditTags&bo='.get_class($this->BO).'&oid='.$this->BO->getOID())."'", "Edit Tags", "tagsBut");
138: $fields['tagsButton'] = $button->render();
139: }
140:
141:
142: $fields['formSecurityFields'] = $this->renderSecurityFields();
143:
144:
145: $fields['version_num'] = $this->BO->getVersionNumber();
146:
147:
148: $fields['fileAttachments'] = $this->renderFileUploadSection();
149:
150: $this->loadTemplate($this->BO, 'edit', $fields);
151:
152: if(method_exists($this, 'after_editView_callback'))
153: $this->after_editView_callback();
154: }
155:
156: 157: 158: 159: 160: 161:
162: protected function renderFileUploadSection() {
163: global $config;
164:
165: $html = '<tr><td colspan="2"> </td></tr><tr><th colspan="2" style="text-align:left;">File Attachments:</th></tr>';
166:
167: if (is_dir($this->BO->getAttachmentsLocation())) {
168: $handle = opendir($this->BO->getAttachmentsLocation());
169:
170: $fileCount = 0;
171:
172:
173: while (false !== ($file = readdir($handle))) {
174: if($file != '.' && $file != '..') {
175: $fileCount++;
176:
177: $html .= '<tr><td>';
178: $html .= ' '.$file.' <em>('.number_format(filesize($this->BO->getAttachmentsLocation().'/'.$file)/1024).' KB)</em>';
179: $html .= '</td>';
180: $html .= '<td>';
181: $js = "$('#dialogDiv').text('Are you sure you want to delete the file ".$file."');
182: $('#dialogDiv').dialog({
183: buttons: {
184: 'OK': function(event, ui) {
185: $('[id=\"".($config->get('security.encrypt.http.fieldnames') ? base64_encode(AlphaSecurityUtils::encrypt('file_to_delete')) : 'file_to_delete')."\"]').attr('value', '".$file."');
186: $('#".get_class($this->BO).'_'.$this->BO->getID()."').submit();
187: },
188: 'Cancel': function(event, ui) {
189: $(this).dialog('close');
190: }
191: }
192: })
193: $('#dialogDiv').dialog('open');
194: return false;";
195: $button = new Button($js, "Delete", "delete".$fileCount."But");
196: $html .= $button->render();
197: $html .= '</td></tr>';
198: }
199: }
200:
201: $html .= '<tr><td>';
202: $html .= 'Attachment file location';
203: $html .= '</td>';
204: }else{
205:
206:
207: $this->BO->createAttachmentsFolder();
208: }
209:
210: $html .= '<td>';
211: $html .= '<input name="userfile" type="file" value="Browse..." size="70"/>';
212: $html .= '</td></tr>';
213:
214: $html .= '<tr><td colspan="2">';
215: $temp = new Button('submit', 'Upload', 'uploadBut');
216: $html .= $temp->render();
217: $html .= '</td></tr>';
218:
219: $fieldname = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(AlphaSecurityUtils::encrypt('file_to_delete')) : 'file_to_delete');
220: $html .= '<input type="hidden" name="'.$fieldname.'" id="'.$fieldname.'" value=""/>';
221:
222: return $html;
223: }
224: }
225:
226: ?>