00001 <?php
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 require_once FASTFRAME_ROOT . 'lib/FastFrame/Action/List.php';
00026
00027
00028
00029
00040
00041 class FF_Action_List_Assignment extends FF_Action_List {
00042
00043
00050 function renderAdditionalLinks()
00051 {
00052 $this->o_output->o_tpl->append('page_links', $this->o_output->link(
00053 '#', sprintf(_('Batch Edit'), $this->getSingularText()),
00054 array('onclick' => 'validateAndSubmit("' . ACTION_BATCH_EDIT . '")')));
00055
00056 $this->o_output->o_tpl->append('page_links', $this->o_output->link(
00057 '#', sprintf(_('Batch Delete'), $this->getSingularText()),
00058 array('onclick' => 'validateAndSubmit("' . ACTION_BATCH_DELETE . '")')));
00059
00060 $this->o_output->o_tpl->append('page_links', $this->o_output->link(
00061 FastFrame::selfURL(array('actionId' => ACTION_ADD)),
00062 sprintf(_('Add New %s'), $this->getSingularText())));
00063 }
00064
00065
00066
00067
00074 function createListTable()
00075 {
00076 $s_html = parent::createListTable();
00077 return '<form action="' . FastFrame::selfURL() . '" name="batch_assignments" method="post">
00078 <input type="hidden" name="actionId" />
00079 ' . $s_html . '
00080 </form>';
00081 }
00082
00083
00084
00085
00094 function getHighlightedRowUrl()
00095 {
00096 return FastFrame::selfURL(array('actionId' => ACTION_EDIT, 'objectId' => $this->o_model->getId()));
00097 }
00098
00099
00100
00101
00109 function getFilter()
00110 {
00111 return array(FILTER_BY_OWNER, array('ownerId' => FF_Auth::getCredential('userId')));
00112 }
00113
00114
00115
00116
00123 function getDefaultSortField()
00124 {
00125 return 'course_code';
00126 }
00127
00128
00129
00130
00137 function getFieldMap()
00138 {
00139 $this->_renderCheckboxJs();
00140 return array(
00141 array('description' => _('Batch Edit'), 'img' => '<input type="checkbox" id="chkbox_toggler" onclick="toggleCheckboxes();" />',
00142 'method' => '_getCheckBox', 'object' => &$this, 'dataIsSafe' => true),
00143 array('description' => _('Options'), 'method' => 'getOptions'),
00144 array('field' => 'course_code', 'description' => _('Course Code'), 'method' => 'getCourseCode'),
00145 array('field' => 'name', 'description' => _('Name'), 'method' => 'getName'),
00146 array('field' => 'session', 'description' => _('Session'), 'method' => 'getSession'),
00147 array('field' => 'open_time', 'description' => _('Open Date'), 'method' => 'getFormattedOpenTime'),
00148 array('field' => 'late_time', 'description' => _('Due Date'), 'method' => 'getFormattedLateTime'),
00149 array('field' => 'close_time', 'description' => _('Close Date'), 'method' => 'getFormattedCloseTime'),
00150 );
00151 }
00152
00153
00154
00155
00163 function getButtonCells()
00164 {
00165 return array('getOptions', '_getCheckBox');
00166 }
00167
00168
00169
00170
00177 function getSingularText()
00178 {
00179 return _('Assignment');
00180 }
00181
00182
00183
00184
00191 function getPluralText()
00192 {
00193 return _('Assignments');
00194 }
00195
00196
00197
00198
00206 function getOptions()
00207 {
00208 $tmp_text = '';
00209 $tmp_text .= $this->o_output->link(
00210 FastFrame::selfURL(array(
00211 'actionId' => ACTION_EDIT, 'objectId' => $this->o_model->getId())),
00212 $this->o_output->imgTag('edit.gif', 'actions'),
00213 array('title' => sprintf (_('Edit %s'), $this->getSingularText())));
00214
00215 $tmp_text .= ' ';
00216 $tmp_text .= $this->o_output->link(
00217 FastFrame::selfURL(array(
00218 'actionId' => ACTION_DELETE, 'objectId' => $this->o_model->getId())),
00219 $this->o_output->imgTag('delete.gif', 'actions'),
00220 array('title' => sprintf (_('Delete %s'), $this->getSingularText()),
00221 'confirm' => sprintf(_('Are you sure you want to delete this %1$s? All ftp data associated with this %1$s will also be deleted!'), $this->getSingularText())));
00222
00223 return $tmp_text;
00224 }
00225
00226
00227
00228
00235 function checkPerms()
00236 {
00237 if (!$this->o_perms->hasPerm('can_use_homework')) {
00238 $this->o_nextAction->setNextActionId(ACTION_PROBLEM);
00239 $this->o_output->setMessage(_('You cannot use the assignment application.'), FASTFRAME_ERROR_MESSAGE);
00240 return false;
00241 }
00242 else {
00243 return true;
00244 }
00245 }
00246
00247
00248
00249
00256 function _getCheckBox()
00257 {
00258 return '<input type="checkbox" name="assignment[' . $this->o_model->getId() . ']" />';
00259 }
00260
00261
00262
00263
00271 function _renderCheckboxJs()
00272 {
00273 ob_start();
00274 ?>
00275 <script language="JavaScript" type="text/javascript">
00276 <!--
00277
00278
00280 function toggleCheckboxes()
00281 {
00282 var ckBx = document.getElementById('listTableHighlight').getElementsByTagName('input')
00283 for (i=0; i < ckBx.length; i++) {
00284 if (ckBx[i].getAttribute('type') == 'checkbox') {
00285 ckBx[i].checked = document.getElementById('chkbox_toggler').checked;
00286 }
00287 }
00288 }
00289
00290
00291
00292
00294 function validateAndSubmit(actionId)
00295 {
00296 if (validateCheckboxes()) {
00297 if (actionId == "<?php echo ACTION_BATCH_DELETE; ?>" &&
00298 !window.confirm("<?php echo _('Are you sure you want to delete the checked assignments? All ftp data associated with these assignments will also be deleted!'); ?>")) {
00299 return false;
00300 }
00301
00302 document.batch_assignments["actionId"].value = actionId;
00303 document.batch_assignments.submit();
00304 return true;
00305 }
00306 else {
00307 return false;
00308 }
00309 }
00310
00311
00312
00313
00315 function validateCheckboxes()
00316 {
00317 var ckBx = document.getElementById('listTableHighlight').getElementsByTagName('input')
00318 for (i=0; i < ckBx.length; i++) {
00319 if (ckBx[i].getAttribute('type') == 'checkbox' &&
00320 ckBx[i].id != 'chkbox_toggler' &&
00321 ckBx[i].checked) {
00322 return true;
00323 }
00324 }
00325
00326 alert("<?php echo _('You must check at least one checkbox in order to use the batch editing feature.'); ?>");
00327 return false;
00328 }
00329
00330
00331
00332 </script>
00333 <?php
00334 $this->o_output->o_tpl->append('javascript', ob_get_contents());
00335 ob_end_clean();
00336 }
00337
00338
00339 }
00340 ?>