Documentation TYPO3 par Ameos |
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 1999-2004 Kasper Skaarhoj (kasperYYYY@typo3.com) 00006 * (c) 2004 Christian Jul Jensen <christian(at)jul(dot)net> 00007 * All rights reserved 00008 * 00009 * This script is part of the TYPO3 project. The TYPO3 project is 00010 * free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. 00014 * 00015 * The GNU General Public License can be found at 00016 * http://www.gnu.org/copyleft/gpl.html. 00017 * A copy is found in the textfile GPL.txt and important notices to the license 00018 * from the author is found in LICENSE.txt distributed with these scripts. 00019 * 00020 * 00021 * This script is distributed in the hope that it will be useful, 00022 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00023 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00024 * GNU General Public License for more details. 00025 * 00026 * This copyright notice MUST APPEAR in all copies of the script! 00027 ***************************************************************/ 00033 require_once (PATH_t3lib.'class.t3lib_tceforms.php'); 00034 require_once (PATH_t3lib.'class.t3lib_tcemain.php'); 00035 00036 class tx_systodos extends mod_user_task { 00037 var $todoTypesCache = array(); 00038 var $insCounter = 0; 00039 var $wfDef = null; 00040 var $wfExe = null; 00041 var $workflowExtIsLoaded = null; 00042 00048 function overview_main() { 00049 return $this->mkMenuConfig( 00050 '<img src="'.$this->backPath.t3lib_extMgm::extRelPath('sys_todos').'ext_icon.gif" width=18 height=16 class="absmiddle">'. $this->headLink('tx_systodos', 1), 00051 '', 00052 $this->renderTaskList(), 00053 'linktitle' ); 00054 00055 } 00056 00062 function main() { 00063 global $SOBE, $BE_USER, $LANG, $BACK_PATH, $TCA_DESCR, $TCA, $CLIENT, $TYPO3_CONF_VARS; 00064 $this->workflowExtIsLoaded = t3lib_extMgm::isLoaded('sys_workflows'); 00065 return $this->renderTasks(); 00066 } 00067 00068 function loadDefinition() { 00069 if ($this->workflowExtIsLoaded) { 00070 if(!is_object($this->wfDef)) { 00071 require_once (t3lib_extMgm::extPath('sys_workflows').'class.tx_sysworkflows_definition.php'); 00072 $this->wfDef = t3lib_div::makeInstance('tx_sysworkflows_definition'); 00073 } 00074 return true; 00075 } else { 00076 return false; 00077 } 00078 } 00079 00080 function loadExecutor() { 00081 if ($this->workflowExtIsLoaded) { 00082 if(!is_object($this->wfExe)) { 00083 require_once (t3lib_extMgm::extPath('sys_workflows').'class.tx_sysworkflows_executor.php'); 00084 $this->wfExe = t3lib_div::makeInstance('tx_sysworkflows_executor'); 00085 $this->wfExe->BE_USER =& $this->BE_USER; 00086 } 00087 return true; 00088 } else { 00089 return false; 00090 } 00091 } 00092 00093 00094 // ************************ 00095 // TODO-tasks 00096 // *********************** 00105 function renderTaskList() { 00106 global $LANG; 00107 00108 $res = $this->exec_todos_getQueryForTodoRels(' AND sys_todos_users_mm.finished_instance=0'); 00109 $userImg = '<img src="'.$this->backPath.'gfx/todoicon_user.gif" width="18" hspace=6 height="10" align=top border=0>'; 00110 $groupImg = '<img src="'.$this->backPath.'gfx/todoicon_group.gif" width="18" hspace=6 height="10" align=top border=0>'; 00111 00112 $lines = array(); 00113 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { 00114 $lines[] = '<nobr>'.($row['cruser_id'] == $this->BE_USER->user['uid']?$userImg:$groupImg).$this->todos_link($this->fixed_lgd($row['title']), -$row['mm_uid']).'</nobr><BR>'; 00115 } 00116 00117 $res = $this->exec_todos_getQueryForTodoRels('', 'count(*)', 1); 00118 list($mc) = $GLOBALS['TYPO3_DB']->sql_fetch_row($res); 00119 $lines[] = '<nobr>'.$this->todos_link(sprintf($LANG->getLL('todos_index_msgs'), $mc), '0').'</nobr><BR>'; 00120 00121 $out = implode('', $lines); 00122 return $out; 00123 } 00124 00132 function todos_link($str, $id) { 00133 $str = '<a href="index.php?SET[function]=tx_systodos&sys_todos_uid='.$id.'#todo" onClick="this.blur();">'.$str.'</a>'; 00134 return $str; 00135 } 00136 00146 function tasks_makeTargetSelector($be_user_Array, $be_group_Array, $type, $returnOptsOnly = 0) { 00147 debug($be_group_Array,'$be_group_Array',__LINE__,__FILE__);//julle 00148 debug($be_user_Array,'$be_user_Array',__LINE__,__FILE__);//julle 00149 00150 global $LANG; 00151 // Plain todo 00152 $opt = array(); 00153 reset($be_user_Array); 00154 $opt[] = '<option value="'.$this->BE_USER->user['uid'].'">'.$this->BE_USER->user['username'].' ['.$LANG->getLL('lSelf').']</option>'; 00155 while (list($uid, $dat) = each($be_user_Array)) { 00156 if ($uid != $this->BE_USER->user['uid']) { 00157 $opt[] = '<option value="'.$uid.'"'.($dat['uid'] == $this->BE_USER->user['uid']?" selected":"").'>'.htmlspecialchars($dat['username'].($dat['uid'] == $this->BE_USER->user['uid']?' ['.$LANG->getLL('lSelf').']':' ('.$dat['realName'].')')).'</option>'; 00158 } 00159 } 00160 if (count($be_group_Array)) { 00161 $opt[] = '<option value="0">'.$LANG->getLL('listSeparator_Groups').'</option>'; 00162 reset($be_group_Array); 00163 while (list($uid, $dat) = each($be_group_Array)) { 00164 $opt[] = '<option value="-'.$uid.'">'.htmlspecialchars($dat['title']).'</option>'; 00165 } 00166 } 00167 if ($returnOptsOnly) return $opt; 00168 return array($LANG->getLL('todos_target').": ", '<select name="data[sys_todos]['.$type.'][target_user]">'.implode('', $opt).'</select>'); 00169 } 00170 00176 function renderTasks() { 00177 global $LANG; 00178 $theCode = ''; 00179 00180 // Setting up general things for the function: 00181 $tUid = intval(t3lib_div::_GP('sys_todos_uid')); 00182 00183 $this->todos_processIncoming($RD_URL); 00184 00185 // Get groupnames for todo-tasks 00186 $this->getUserAndGroupArrays(); // Users and groups blinded due to permissions, plus (third) the original user array with all users 00187 // debug($this->userGroupArray); 00188 00189 // Create Todo types array (workflows): 00190 $todoTypes = array(); 00191 $todoTypes['plain'] = '['.$LANG->getLL('todos_plain').']'; 00192 if ($this->loadDefinition()) { 00193 $todoTypes += $this->wfDef->getWorkflowTypes($this->BE_USER); 00194 } 00195 // Printing the todo list of a user: 00196 $theCode .= $this->todos_displayLists($todoTypes, $tUid); 00197 00198 // Display todo: 00199 00200 00201 if($RD_URL) { 00202 $theCode .= $this->urlInIframe($RD_URL); 00203 } elseif ($tUid) { 00204 $theCode .= $this->todos_displayTodo($todoTypes, $tUid); 00205 } 00206 00207 00208 // New todo: 00209 $theCode .= $this->todos_createForm($todoTypes); 00210 00211 return $theCode; 00212 } 00213 00223 function todos_finalizeWorkflow($workflowRecord, $relRecord) { 00224 global $TCA; 00225 list($table, $uid) = explode(':', $relRecord['rec_reference']); 00226 if ($workflowRecord['tablename'] == $table && $TCA[$table]) { 00227 $itemRecord = t3lib_BEfunc::getRecord($table, $uid); 00228 if (is_array($itemRecord)) { 00229 if('-1' == $itemRecord['pid']) { 00230 // this is a versionized page, should be published, not moved 00231 $this->wfExe->publishNewVersion($table,$itemRecord['t3ver_oid'],$uid); 00232 } else { 00233 list($target_pid) = explode(',', $workflowRecord['final_target']); 00234 $this->wfExe->publishNewRecord($table,$uid,$target_pid,$workflowRecord['final_unhide'],$workflowRecord); 00235 } 00236 return true; 00237 } else { 00238 debug('ERROR: The reference record was not there!'); 00239 } 00240 } else { 00241 debug('ERROR: Strange thing, the table name was not valid!'); 00242 } 00243 } 00244 00253 function todos_beginWorkflow($workflowRecord) { 00254 global $TCA; 00255 00256 list($working_area_pid) = explode(',', $workflowRecord['working_area']); 00257 $table = $workflowRecord['tablename']; 00258 $workingPage = t3lib_BEfunc::getRecord('pages', $working_area_pid); 00259 $versioningPage = t3lib_BEfunc::getRecord('pages', $workflowRecord['existing_record']); 00260 if (is_array($workingPage) && $TCA[$table]) { 00261 return $this->wfExe->createNewRecord($table,$workingPage['uid']); 00262 } elseif(is_array($versioningPage)) { 00263 return $this->wfExe->createNewVersionOfRecord($table,$versioningPage['uid']); 00264 } else { 00265 debug('', 'ERROR: No working area page for workflow is defined!', __LINE__, __FILE__); 00266 } 00267 } 00268 00275 function todos_processIncoming(&$RD_URL) { 00276 global $LANG; 00277 00278 // PROCESSING: 00279 $data = t3lib_div::_GP('data'); 00280 00281 // ******************************** 00282 // Instance updated 00283 // ******************************** 00284 if (t3lib_div::_GP('newStatus') && is_array($data['sys_todos_users_mm'])) { 00285 // A status is updated 00286 00287 $RD_URL = ''; 00288 debug($data['sys_todos_users_mm'],'$data[\'sys_todos_users_mm\']',__LINE__,__FILE__); 00289 00290 reset($data['sys_todos_users_mm']); 00291 while (list($key) = each($data['sys_todos_users_mm'])) { 00292 $key = intval($key); 00293 $res = $this->exec_todos_getQueryForTodoRels(' AND sys_todos_users_mm.mm_uid='.$key, 'sys_todos_users_mm.*,sys_todos.cruser_id,sys_todos.type', 1); 00294 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { 00295 if ($data['sys_todos_users_mm'][$key]['status']['code'] > 0) { 00296 $wF = $row['type']; 00297 if (substr($wF, 0, 3) == "wf_" && $this->workflowExtIsLoaded) { 00298 $workflowRecord = t3lib_BEfunc::getRecord('sys_workflows', substr($wF, 3)); 00299 } else { 00300 unset($workflowRecord); 00301 } 00302 00303 $noUpdate = 0; 00304 // debug($row); 00305 00306 $status_log = unserialize($row['status_log']); 00307 if (!is_array($status_log)) $status_log = array(); 00308 $statLogDat = array( 00309 'code' => $data['sys_todos_users_mm'][$key]['status']['code'], 00310 'issuer' => $GLOBALS['BE_USER']->user['uid'], 00311 'tstamp' => time(), 00312 'uid_foreign_before' => $row['uid_foreign'], 00313 'comment' => $data['sys_todos_users_mm'][$key]['status']['comment'] ); 00314 00315 $field_values = array(); 00316 $field_values['status'] = $data['sys_todos_users_mm'][$key]['status']['code']; 00317 $field_values['tstamp'] = time(); 00318 $field_values['is_read'] = 0; // Not used yet, but the point is that this flag is set when a target users looks at the item for the first time. This may later be used to inform the owner of the item whether it has been looked at or not. Here it's reset for every change to the log. Maybe it should be changed for each new target only.? 00319 00320 // target: 00321 switch($field_values['status']) { 00322 case 1: 00323 // todos_status_comment, no change of target 00324 break; 00325 case 2: 00326 // todos_status_begin, no change of target (at this point) 00327 if ($this->loadExecutor() && is_array($workflowRecord) && $workflowRecord['tablename'] && !$row['rec_reference']) { 00328 $recId = $this->todos_beginWorkflow($workflowRecord); 00329 if ($recId) { 00330 $field_values['rec_reference'] = $recId; 00331 $RD_URL = $this->getEditRedirectUrlForReference($recId); 00332 } else { 00333 debug('ERROR: The record was not created, so either the workflow is not properly configured or the user did not have permissions to create the record (check the system log for details if this is the case)'); 00334 } 00335 } else { 00336 debug('ERROR: No workflow record found OR no tablename defined OR there was already a record reference in the record!'); 00337 } 00338 break; 00339 case 3: 00340 // todos_status_end, pass on to reviewer if found (may select reviewer in form), else back to admin 00341 $first = 0; 00342 // Trying to find a review user if any and apply this user instead of the owner. 00343 if ($this->workflowExtIsLoaded && is_array($workflowRecord) && $workflowRecord['tablename']) { 00344 $revUsers = $this->todos_getReviewUsers($workflowRecord['uid']); 00345 reset($revUsers); 00346 while (list($u_id) = each($revUsers)) { 00347 // CHECK IF the submittet target user matches one of the reviewers 00348 if (!$first) $first = $u_id; 00349 if ($u_id == $data['sys_todos_users_mm'][$key]['status']['newTarget']) { 00350 $field_values['uid_foreign'] = $u_id; 00351 break; 00352 } 00353 } 00354 00355 } 00356 if (!$field_values['uid_foreign']) { 00357 // IF the target is NOT found yet (may have been between the submitted targets.) 00358 $field_values['uid_foreign'] = $first ? $first : 00359 $row['cruser_id']; // ... select the first review user and if that is not set, select the owner 00360 } 00361 break; 00362 case 4: 00363 // todos_status_passOn, just pass on to selected target 00364 if (intval($data['sys_todos_users_mm'][$key]['status']['newTarget'])) { 00365 $field_values['uid_foreign'] = $data['sys_todos_users_mm'][$key]['status']['newTarget']; 00366 } 00367 break; 00368 case 5: 00369 // todos_status_reject, target = sender user 00370 $field_values['uid_foreign'] = $row['cruser_id']; 00371 break; 00372 00373 00374 case 100: 00375 // Reset status-log 00376 if ($this->BE_USER->user['uid'] == $row['cruser_id']) { 00377 // Must own 00378 $statLogDat['status_log_clear'] = 1; 00379 } else { 00380 $noUpdate = 1; 00381 } 00382 break; 00383 case 103: 00384 // Finalize 00385 if ($this->loadExecutor() && $this->BE_USER->user['uid'] == $row['cruser_id']) { 00386 // Must own 00387 $field_values['uid_foreign'] = $row['cruser_id']; 00388 $field_values['finalized'] = $this->todos_finalizeWorkflow($workflowRecord, $row) ? 1 : 00389 0; 00390 } else { 00391 $noUpdate = 1; 00392 } 00393 break; 00394 /* case 101: 00395 if ($this->BE_USER->user['uid']==$row['cruser_id']) { // Must own 00396 $field_values['deleted']=1; 00397 // debug('DELETE'); 00398 } 00399 break; 00400 */ case 102: 00401 if ($this->BE_USER->user['uid'] == $row['cruser_id']) { 00402 // Must own 00403 $statLogDat['uid_foreign'] = $data['sys_todos_users_mm'][$key]['status']['newTarget']; 00404 00405 $field_values = array( 00406 'uid_local' => $row['uid_local'], 00407 'uid_foreign' => $statLogDat['uid_foreign'], 00408 'status' => 102, 00409 'tstamp' => time(), 00410 'status_log' => serialize(array($statLogDat)) 00411 ); 00412 00413 $GLOBALS['TYPO3_DB']->exec_INSERTquery('sys_todos_users_mm', $field_values); 00414 00415 $noUpdate = 1; 00416 } 00417 break; 00418 } 00419 00420 if (!$noUpdate) { 00421 if (isset($field_values['uid_foreign'])) $statLogDat['uid_foreign'] = $field_values['uid_foreign']; 00422 $status_log[] = $statLogDat; 00423 $field_values['status_log'] = serialize($status_log); 00424 00425 $GLOBALS['TYPO3_DB']->exec_UPDATEquery('sys_todos_users_mm', "mm_uid=".intval($key), $field_values); 00426 } 00427 } 00428 00429 // Finished? 00430 if (isset($data['sys_todos_users_mm'][$key]['finished_instance']) && $this->BE_USER->user['uid'] == $row['cruser_id']) { 00431 00432 $field_values = array( 00433 'finished_instance' => $data['sys_todos_users_mm'][$key]['finished_instance']?1: 00434 0 ); 00435 $GLOBALS['TYPO3_DB']->exec_UPDATEquery('sys_todos_users_mm', 'mm_uid='.intval($key), $field_values); 00436 } 00437 } 00438 } 00439 00440 00441 // If redirect, do that. 00442 // if ($RD_URL) { 00443 // header('Location: '.t3lib_div::locationHeaderUrl($RD_URL)); 00444 // } 00445 } 00446 00447 // *********************************** 00448 // sys_todos are created/updated 00449 // *********************************** 00450 if (t3lib_div::_GP('create_todo') && is_array($data['sys_todos'])) { 00451 // A todo is created 00452 reset($data['sys_todos']); 00453 $key = key($data['sys_todos']); 00454 if ($key == 'NEW') { 00455 # debug($data,'$data',__LINE__,__FILE__); 00456 if ($data['sys_todos'][$key]['target_user'] && $data['sys_todos'][$key]['type'] && $data['sys_todos'][$key]['title']) { 00457 00458 $fields_values = array( 00459 'title' => $data['sys_todos'][$key]['title'], 00460 'type' => $data['sys_todos'][$key]['type'], 00461 'deadline' => $data['sys_todos'][$key]['deadline'], 00462 'description' => $data['sys_todos'][$key]['description'], 00463 'deleted' => 0, 00464 'finished' => 0, 00465 'tstamp' => time(), 00466 'crdate' => time(), 00467 'cruser_id' => $this->BE_USER->user['uid'] ); 00468 $GLOBALS['TYPO3_DB']->exec_INSERTquery('sys_todos', $fields_values); 00469 00470 // Relation: 00471 if (!$GLOBALS['TYPO3_DB']->sql_error()) { 00472 $fields_values = array( 00473 'uid_local' => $GLOBALS['TYPO3_DB']->sql_insert_id(), 00474 'uid_foreign' => $data['sys_todos'][$key]['target_user'], 00475 'tstamp' => time() 00476 ); 00477 $GLOBALS['TYPO3_DB']->exec_INSERTquery('sys_todos_users_mm', $fields_values); 00478 } 00479 00480 // SEnding email notification and filling the emRec array: 00481 $tempQ = FALSE; 00482 $emRec = array(); 00483 if ($data['sys_todos'][$key]['target_user'] > 0) { 00484 // Ordinary user 00485 $tempQ = TRUE; 00486 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid,username,realName,email', 'be_users', 'uid='.intval($data['sys_todos'][$key]['target_user']).t3lib_BEfunc::deleteClause('be_users')); 00487 } 00488 if ($data['sys_todos'][$key]['target_user'] < 0) { 00489 // Users in group 00490 $tempQ = TRUE; 00491 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid,username,realName,email', 'be_users', $GLOBALS['TYPO3_DB']->listQuery('usergroup_cached_list', abs($data['sys_todos'][$key]['target_user']), 'be_users').t3lib_BEfunc::deleteClause('be_users')); 00492 } 00493 if ($tempQ) { 00494 $sAE = t3lib_div::_GP('sendAsEmail'); // This flag must be set in order for the email to get sent 00495 while ($brow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { 00496 $sendM = 0; 00497 if ($sAE && strstr($brow['email'], '@') && $brow['uid'] != $this->BE_USER->user['uid']) { 00498 // Send-flag must be set, the user must have an email address and finally mails are not sent to the creating user, should he be in the group. 00499 $this->sendEmail($brow['email'], $data['sys_todos'][$key]['title'], $data['sys_todos'][$key]['description']); 00500 $sendM = 1; 00501 } 00502 $emRec[] = $brow['username'].($sendM ? " (".$brow['email'].")" : ""); 00503 } 00504 } 00505 if (count($emRec)) { 00506 // $emRec just stores the users which is in the target group/target-user and here the list is displayed for convenience. 00507 $emailList = implode('<BR> ', $emRec); 00508 $theCode .= $this->pObj->doc->section($LANG->getLL('todos_created'), $LANG->getLL('todos_created_msg').'<BR> '.$emailList, 0, 1, 1); 00509 } 00510 } else { 00511 // $theCode.= $this->pObj->doc->section($LANG->getLL('todos_created'),$this->errorIcon().$GLOBALS['TBE_TEMPLATE']->rfw($LANG->getLL('todos_createdError_msg')),0,1); 00512 } 00513 } else { 00514 // Edit todo: 00515 $editRow = t3lib_BEfunc::getRecordRaw('sys_todos', "uid=".$key); 00516 if (is_array($editRow) && $editRow['cruser_id'] == $this->BE_USER->user['uid'] && $data['sys_todos'][$key]['title']) { 00517 $fields_values = array( 00518 'title' => $data['sys_todos'][$key]['title'], 00519 'deadline' => $data['sys_todos'][$key]['deadline'], 00520 'description' => $data['sys_todos'][$key]['description'], 00521 'tstamp' => time() 00522 ); 00523 $GLOBALS['TYPO3_DB']->exec_UPDATEquery('sys_todos', 'uid='.intval($key), $fields_values); 00524 } 00525 } 00526 } 00527 00528 00529 // ************************************************* 00530 // sys_todos / instances are updated regarding DONE 00531 // ************************************************* 00532 if (t3lib_div::_GP('marked_todos')) { 00533 $action = t3lib_div::_GP('marked_todos_action'); 00534 $done = t3lib_div::_GP('DONE'); 00535 if (is_array($done)) { 00536 while (list($uidKey, $value) = each($done)) { 00537 $uidKey = intval($uidKey); 00538 if ($uidKey < 0) { 00539 $uidKey = abs($uidKey); 00540 $sys_todos_users_mm_row = t3lib_BEfunc::getRecordRaw('sys_todos_users_mm', "mm_uid=".$uidKey); 00541 if (is_array($sys_todos_users_mm_row)) { 00542 $sys_todos_row = t3lib_BEfunc::getRecordRaw('sys_todos', "uid=".intval($sys_todos_users_mm_row['uid_local'])); 00543 if (is_array($sys_todos_row) && $sys_todos_row['cruser_id'] == $this->BE_USER->user['uid']) { 00544 00545 $fields_values = array( 00546 'finished_instance' => $value?1: 00547 0 ); 00548 if ($action == 127 && $value) $fields_values['deleted'] = 1; 00549 00550 $GLOBALS['TYPO3_DB']->exec_UPDATEquery('sys_todos_users_mm', "mm_uid=".intval($uidKey), $fields_values); 00551 00552 // Check if there are any sys_todos_users_mm left, which are not deleted. If there are not, delete the sys_todos item 00553 $isNotDeleted = t3lib_BEfunc::getRecordRaw('sys_todos_users_mm', "uid_local=".intval($sys_todos_row['uid']).' AND deleted=0'); 00554 if (!is_array($isNotDeleted)) { 00555 // Delete sys_todos 00556 $fields_values = array( 00557 'finished' => 1, 00558 'deleted' => 1 ); 00559 $GLOBALS['TYPO3_DB']->exec_UPDATEquery('sys_todos', "uid=".intval($sys_todos_row['uid']), $fields_values); 00560 } 00561 } 00562 } 00563 00564 } else { 00565 $sys_todos_row = t3lib_BEfunc::getRecordRaw('sys_todos', "uid=".intval($uidKey)); 00566 if (is_array($sys_todos_row) && $sys_todos_row['cruser_id'] == $this->BE_USER->user['uid']) { 00567 $fields_values = array('finished' => $value?1:0); 00568 if ($action == 127 && $value) $fields_values['deleted'] = 1; 00569 00570 $GLOBALS['TYPO3_DB']->exec_UPDATEquery('sys_todos', "uid=".$uidKey, $fields_values); 00571 00572 // Also set status for instances, if they are checked for main item: 00573 if ($fields_values['deleted']) { 00574 $inst_fields_values = array('deleted' => 1); 00575 00576 // Update all relations to the sys_todos 00577 $GLOBALS['TYPO3_DB']->exec_UPDATEquery('sys_todos_users_mm', "uid_local=".intval($uidKey), $inst_fields_values); 00578 } 00579 } 00580 } 00581 } 00582 } 00583 } 00584 return $theCode; 00585 } 00586 00594 function todos_workflowTitle($todoTypes, $type) { 00595 if (!isset($this->todoTypesCache[$type])) { 00596 if (isset($todoTypes[$type])) { 00597 $this->todoTypesCache[$type] = $todoTypes[$type]; 00598 } elseif (substr($type, 0, 3) == "wf_" && $this->workflowExtIsLoaded) { 00599 $workflowRecord = t3lib_BEfunc::getRecord('sys_workflows', substr($type, 3)); 00600 $this->todoTypesCache[$type] = $workflowRecord['title']; 00601 } 00602 } 00603 return $this->todoTypesCache[$type]; 00604 } 00605 00613 function todos_displayTodo($todoTypes, $tUid) { 00614 global $LANG; 00615 00616 if ($tUid > 0) { 00617 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_todos', 'uid='.intval($tUid).' AND cruser_id='.intval($this->BE_USER->user['uid']).' AND NOT deleted'); 00618 } else { 00619 $res = $this->exec_todos_getQueryForTodoRels(' AND sys_todos_users_mm.mm_uid='.abs($tUid)); 00620 } 00621 00622 $msg = array(); 00623 $workflowRecord = ''; 00624 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { 00625 $editIcon = $row['cruser_id'] == $this->BE_USER->user['uid'] ? '<a href="index.php?sys_todos_uid='.$tUid.'&editTodo=1#todo"><img src="'.$this->backPath.'gfx/edit2.gif" width="11" height="12" vspace=2 border="0" align=top></a>' : 00626 ''; 00627 $iconName = 'tc_todos'.($row['cruser_id'] == $this->BE_USER->user['uid']?'':'_foreign').'.gif'; 00628 $header = '<nobr><img src="'.$this->backPath.'gfx/i/'.$iconName.'" width="18" height="16" hspace=2 border=0 align=top title="'.$LANG->getLL('todos_item').' #'.$row['uid'].'">'.$editIcon.' <strong>'.htmlspecialchars($row['title']).'</strong></nobr><BR>'; 00629 $formA = array(); 00630 $formA[] = array($LANG->getLL('todos_createdBy').": ", $this->userGroupArray[2][$row['cruser_id']]['username'].' ('.$this->userGroupArray[2][$row['cruser_id']]['realName'].'), '.$this->dateTimeAge($row['crdate'], -1)); 00631 $dLine = $this->dateTimeAge($row['deadline'], -1).' '; 00632 if ($row['deadline'] < time()) $dLine = '<span class="typo3-red">'.$dLine.'</span>'; 00633 $formA[] = array($LANG->getLL('todos_deadline').": ", $dLine); 00634 $formA[] = array($LANG->getLL('todos_description').": ", nl2br($row['description']).' '); 00635 00636 if ($row['type'] && $row['type'] != 'plain') { 00637 $formA[] = array($LANG->getLL('todos_type').": ", $this->todos_workflowTitle($todoTypes, $row['type'])); 00638 $wF = $row['type']; 00639 if (substr($wF, 0, 3) == "wf_" && $this->workflowExtIsLoaded) { 00640 $workflowRecord = t3lib_BEfunc::getRecord('sys_workflows', substr($wF, 3)); 00641 if (is_array($workflowRecord) && $workflowRecord['tablename']) { 00642 $formA[] = array($LANG->getLL('todos_workflowDescr').": ", $workflowRecord['description']); 00643 // debug($workflowRecord); 00644 } 00645 } 00646 } 00647 00648 $msg[] = $header.$this->pObj->doc->table($formA); 00649 00650 if (!t3lib_div::_GP('editTodo')) { 00651 $res = $GLOBALS['TYPO3_DB']->exec_SELECT_mm_query( 00652 'sys_todos_users_mm.*', 00653 'sys_todos', 00654 "sys_todos_users_mm", 00655 '', 00656 "AND NOT sys_todos_users_mm.deleted AND NOT sys_todos.deleted".($tUid < 0?" AND sys_todos_users_mm.mm_uid=":" AND sys_todos.uid=").abs($tUid) 00657 ); 00658 00659 // Display todo log: 00660 $this->insCounter = 0; 00661 while ($rel_row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { 00662 $msg[] = '<HR>'.$this->todos_printStatus($rel_row, $row, $workflowRecord, $tUid, $GLOBALS['TYPO3_DB']->sql_num_rows($res)); 00663 } 00664 $msg[] = '<BR><input type="submit" name="newStatus" value="'.$LANG->getLL('todos_newStatus').'"> <input type="submit" name="cancel" value="'.$LANG->getLL('lCancel').'" onClick="document.editform.sys_todos_uid.value=0;"> 00665 <input type="hidden" name="sys_todos_uid" value="'.$tUid.'"><BR>'; 00666 } 00667 00668 if (count($msg)) { 00669 $theCode .= $this->pObj->doc->spacer(20); 00670 $theCode .= $this->pObj->doc->section('<a name="todo"></a>'.$LANG->getLL('todo_details', 1), implode('', $msg), 0, 1, 0, 1); 00671 } 00672 00673 // Edit form: 00674 if (t3lib_div::_GP('editTodo') && $row['cruser_id'] == $this->BE_USER->user['uid']) { 00675 $theCode .= $this->todos_createForm($todoTypes, $row); 00676 } 00677 } 00678 return $theCode; 00679 } 00680 00691 function todos_printStatus($rel_row, $todo_row, $workflow_row, $tUid, $countOfInstances = 0) { 00692 global $LANG, $TCA; 00693 00694 if ($this->workflowExtIsLoaded && is_array($workflow_row)) { 00695 $revUsers = $this->todos_getReviewUsers($workflow_row['uid']); 00696 } 00697 else $revUsers = array(); 00698 00699 $noExtraFields = 0; 00700 00701 $theCode = ''; 00702 $statusLabels = array(); 00703 $statusLabels[1] = htmlspecialchars($LANG->getLL('todos_status_comment')); 00704 $statusLabels[2] = htmlspecialchars($LANG->getLL('todos_status_begin')); 00705 $statusLabels[3] = htmlspecialchars($LANG->getLL('todos_status_end')); 00706 $statusLabels[4] = htmlspecialchars($LANG->getLL('todos_status_passOn')); 00707 $statusLabels[5] = htmlspecialchars($LANG->getLL('todos_status_reject')); 00708 00709 $statusLabels[100] = htmlspecialchars($LANG->getLL('todos_status_resetStatus')); 00710 $statusLabels[103] = htmlspecialchars($LANG->getLL('todos_status_finalize')); 00711 // $statusLabels[101]=htmlspecialchars($LANG->getLL('todos_status_delete')); 00712 $statusLabels[102] = htmlspecialchars($LANG->getLL('todos_status_newInstance')); 00713 00714 $allowedTargetCodes = '2,3,4,102'; 00715 00716 $this->insCounter++; 00717 //$this->insCounter.' / 00718 $iSt = ' ('.$LANG->getLL('todos_instance').' #'.$rel_row['mm_uid'].')'; 00719 00720 $theCode .= '<BR><strong>'.$LANG->getLL('todos_logEntries').$iSt.':</strong><BR>'; 00721 $log = unserialize($rel_row['status_log']); 00722 $prevUsersGroups = array(); 00723 if (is_array($log)) { 00724 $lines = array(); 00725 00726 reset($log); 00727 $c = 0; 00728 while (list(, $logDat) = each($log)) { 00729 $prevUsersGroups[] = $logDat['uid_foreign_before']; 00730 // debug($logDat); 00731 if ($logDat['status_log_clear']) { 00732 $c = 0; 00733 $lines = array(); 00734 } 00735 00736 $c++; 00737 $bgColorClass = ($c+1)%2 ? 'bgColor' : 00738 'bgColor-10'; 00739 $lines[] = '<tr class="'.$bgColorClass.'"> 00740 <td valign=top nowrap width=10%>'. '<strong>'.$statusLabels[$logDat['code']].'</strong><BR>'. $this->printUserGroupName($logDat['issuer']).'<BR>'. $this->dateTimeAge($logDat['tstamp'], 1).'<BR>'. (isset($logDat['uid_foreign']) ? "<em>".$LANG->getLL('todos_logEntries_lTarget').'</em>:<BR>'.$this->printUserGroupName($logDat['uid_foreign']).'<BR>' : ''). '<BR></td> 00741 <td valign=top> </td> 00742 <td valign=top width=80%>'.nl2br(htmlspecialchars($logDat['comment'])).'</td> 00743 </tr>'; 00744 } 00745 00746 array_unshift($lines, '<tr class="bgColor5"> 00747 <td nowrap><strong>'.$LANG->getLL('todos_logEntries_lStatusInfo').':</strong></td> 00748 <td> </td> 00749 <td nowrap><strong>'.$LANG->getLL('todos_logEntries_lDetails').':</strong></td> 00750 </tr>'); 00751 00752 $theCode .= '<table border=0 cellpadding=0 cellspacing=0 width="100%">'.implode('', $lines).'</table>'; 00753 } else { 00754 $theCode .= $LANG->getLL('todos_logEntries_msg1').'<br>'; 00755 } 00756 if ($rel_row['uid_foreign']) { 00757 $theCode .= '<BR>'.$LANG->getLL('todos_logEntries_lTargetedAt').': <strong>'.$this->printUserGroupName($rel_row['uid_foreign'], 1).'</strong><BR>'; 00758 } else { 00759 $theCode .= '<BR><strong>'.$LANG->getLL('todos_logEntries_lnoTarget').'</strong>'; 00760 } 00761 00762 if ($rel_row['rec_reference']) { 00763 $theCode .= '<BR>'.$LANG->getLL('todos_logEntries_lRecordRelated').':<br>'; 00764 $recRelParts = explode(':', $rel_row['rec_reference']); 00765 $recordRelated = t3lib_BEfunc::getRecord($recRelParts[0], $recRelParts[1]); 00766 if ($recordRelated) { 00767 $theCode .= '<a href="'.$this->getEditRedirectUrlForReference($rel_row['rec_reference']).'"><img src="'.$this->backPath.'gfx/edit2.gif" width="11" height="12" hspace=3 vspace=2 border="0" align=top></a>'. ($recRelParts[0] == "pages" ? $this->pObj->doc->viewPageIcon($recRelParts[1], $this->backPath, 'align=top hspace=2') : ""). t3lib_iconWorks::getIconImage($recRelParts[0], $recordRelated, $this->backPath, ' align="top" hspace="2"'). htmlspecialchars($recordRelated[$TCA[$recRelParts[0]]['ctrl']['label']]); 00768 } else { 00769 $theCode .= '<span class="typo3-red"><strong>'.$LANG->getLL('todos_errorNoRecord').'</strong></span>'; 00770 } 00771 00772 } 00773 $theCode .= '<BR><BR>'; 00774 00775 // **************************** 00776 // Status selector 00777 // **************************** 00778 $opt = Array(); 00779 $statusLabels_copy = $statusLabels; 00780 00781 // Unset certain items which we do not present in the menu under certain circumstances. 00782 if (!is_array($workflow_row) || !$workflow_row['tablename'] || $rel_row['rec_reference']) unset($statusLabels_copy[2]); 00783 if (!is_array($workflow_row) || !$workflow_row['tablename'] || !$rel_row['rec_reference']) unset($statusLabels_copy[103]); 00784 if (!count($revUsers) || (!$rel_row['rec_reference'] && is_array($workflow_row))) unset($statusLabels_copy[3]); 00785 if ($this->BE_USER->user['uid'] != $todo_row['cruser_id']) { 00786 unset($statusLabels_copy[100]); 00787 // unset($statusLabels_copy[101]); 00788 unset($statusLabels_copy[102]); 00789 unset($statusLabels_copy[103]); 00790 } else { 00791 unset($statusLabels_copy[5]); 00792 } 00793 00794 if ($tUid < 0) unset($statusLabels_copy[102]); 00795 // Don't allow new instance creation if we're not looking at the TODO item but an instance. 00796 00797 // If finalized: 00798 if ($rel_row['finalized']) { 00799 $statusLabels_copy = array(); 00800 if ($this->BE_USER->user['uid'] == $todo_row['cruser_id']) { 00801 // $statusLabels_copy[101] = $statusLabels[101]; 00802 $statusLabels_copy[102] = $statusLabels[102]; 00803 $noExtraFields = 1; 00804 } 00805 } 00806 00807 $formCodeAccu = ''; 00808 if (count($statusLabels_copy)) { 00809 reset($statusLabels_copy); 00810 if ($countOfInstances > 1 || $this->BE_USER->user['uid'] == $todo_row['cruser_id']) $opt[] = '<option value="0"></option>'; 00811 while (list($kk, $vv) = each($statusLabels_copy)) { 00812 $opt[] = '<option value="'.$kk.'">'.$vv.'</option>'; 00813 } 00814 $onChange = "var allowedCodes=',".$allowedTargetCodes.",'; 00815 if (allowedCodes.indexOf(','+this.options[this.selectedIndex].value+',')==-1) { 00816 document.editform['data[sys_todos_users_mm][".$rel_row['mm_uid']."][status][newTarget]'].selectedIndex=0; 00817 }"; 00818 $formCodeAccu .= htmlspecialchars($LANG->getLL('todos_status_addStatus')).':<BR><select name="data[sys_todos_users_mm]['.$rel_row['mm_uid'].'][status][code]" onChange="'.$onChange.'">'.implode('', $opt).'</select><BR>'; 00819 00820 if (!$noExtraFields) { 00821 $opt = Array(); 00822 $opt[] = '<option value="0"></option>'; 00823 // $opt[]='<option value="0">[ '.htmlspecialchars($LANG->getLL('todos_selectTargetUG')).' ]</option>'; 00824 00825 // Sender 00826 $revUserRec = t3lib_BEfunc::getRecord('be_users', $todo_row['cruser_id']); 00827 $opt[] = '<option value="'.$todo_row['cruser_id'].'">'.htmlspecialchars($LANG->getLL('todos_sender').': '.$revUserRec['username'].($revUserRec['realName']?" (".$revUserRec['realName'].")":"")).'</option>'; 00828 00829 // Review users: 00830 reset($revUsers); 00831 while (list($u_id, $revUserRec) = each($revUsers)) { 00832 // CHECK IF they 00833 $opt[] = '<option value="'.$u_id.'">'.htmlspecialchars($LANG->getLL('todos_reviewer').': '.$revUserRec['username'].($revUserRec['realName']?" (".$revUserRec['realName'].")":"")).'</option>'; 00834 } 00835 00836 // Users through time: 00837 $prevUsersGroups[] = $this->BE_USER->user['uid']; 00838 $prevUsersGroups[] = $rel_row['uid_foreign']; 00839 if (is_array($prevUsersGroups) && count($prevUsersGroups)) { 00840 $opt[] = '<option value="0"></option>'; 00841 $opt[] = '<option value="0">'.htmlspecialchars($LANG->getLL('todos_pastUG')).'</option>'; 00842 $prevUsersGroups = array_unique($prevUsersGroups); 00843 reset($prevUsersGroups); 00844 while (list(, $UGuid) = each($prevUsersGroups)) { 00845 if ($UGuid) $opt[] = '<option value="'.$UGuid.'">'.htmlspecialchars(($UGuid > 0?$LANG->getLL('todos_user'):$LANG->getLL('todos_group')).': '.$this->printUserGroupName($UGuid)).'</option>'; 00846 } 00847 } 00848 00849 if ($this->BE_USER->user['uid'] == $todo_row['cruser_id']) { 00850 $opt[] = '<option value="0"></option>'; 00851 $opt[] = '<option value="0">'.htmlspecialchars($LANG->getLL('todos_allUG')).'</option>'; 00852 00853 if ($todo_row['type'] == 'plain') { 00854 $opt = array_merge($opt, $this->tasks_makeTargetSelector($this->userGroupArray[0], $this->userGroupArray[1], 0, 1)); 00855 } elseif (is_array($workflow_row)) { 00856 $grL = implode(',', t3lib_div::intExplode(',', $workflow_row['target_groups'])); 00857 $wf_groupArray = t3lib_BEfunc::getGroupNames('title,uid', "AND uid IN (".($grL?$grL:0).')'); 00858 $wf_userArray = t3lib_BEfunc::blindUserNames($this->userGroupArray[2], array_keys($wf_groupArray), 1); 00859 $opt = array_merge($opt, $this->tasks_makeTargetSelector($wf_userArray, $wf_groupArray, 0, 1)); 00860 } 00861 } 00862 00863 $onChange = "var allowedCodes=',".$allowedTargetCodes.",'; 00864 if (allowedCodes.indexOf( 00865 ',' 00866 + document.editform['data[sys_todos_users_mm][".$rel_row['mm_uid']."][status][code]'].options[document.editform['data[sys_todos_users_mm][".$rel_row['mm_uid']."][status][code]'].selectedIndex].value 00867 +',')==-1 || this.options[this.selectedIndex].value==0) { 00868 this.selectedIndex=0; 00869 }"; 00870 $formCodeAccu .= htmlspecialchars($LANG->getLL('todos_status_selectTarget')).':<BR><select name="data[sys_todos_users_mm]['.$rel_row['mm_uid'].'][status][newTarget]" onChange="'.$onChange.'">'.implode('', $opt).'</select><BR>'; 00871 00872 $formCodeAccu .= htmlspecialchars($LANG->getLL('todos_statusNote')).':<BR><textarea rows="10" name="data[sys_todos_users_mm]['.$rel_row['mm_uid'].'][status][comment]"'.$this->pObj->doc->formWidthText(40, '', '').'></textarea><BR>'; 00873 } 00874 } 00875 if ($this->BE_USER->user['uid'] == $todo_row['cruser_id']) { 00876 $formCodeAccu .= '<input type="hidden" name="data[sys_todos_users_mm]['.$rel_row['mm_uid'].'][finished_instance]" value="0"><input type="checkbox" name="data[sys_todos_users_mm]['.$rel_row['mm_uid'].'][finished_instance]" value="1"'.($rel_row['finished_instance']?" checked":"").'>'. htmlspecialchars($LANG->getLL('todos_finished')); 00877 } 00878 00879 00880 return $theCode.$formCodeAccu; 00881 } 00882 00889 function negateList($list) { 00890 $listArr = explode(',', $list); 00891 while (list($k, $v) = each($listArr)) { 00892 $listArr[$k] = $v * -1; 00893 } 00894 // debug(implode(',',$listArr)); 00895 return implode(',', $listArr); 00896 } 00897 00906 function exec_todos_getQueryForTodoRels($extraWhere = "", $selectFields = "", $allowOwn = 0) { 00907 $groupQ = $this->BE_USER->user['usergroup_cached_list'] ? " OR sys_todos_users_mm.uid_foreign IN (".$this->negateList($this->BE_USER->user['usergroup_cached_list']).")" : 00908 ""; 00909 if ($allowOwn) $groupQ .= ' OR sys_todos.cruser_id='.intval($this->BE_USER->user['uid']); 00910 00911 return $GLOBALS['TYPO3_DB']->exec_SELECT_mm_query( 00912 $selectFields?$selectFields: 00913 "sys_todos.*,sys_todos_users_mm.mm_uid,sys_todos_users_mm.uid_foreign,sys_todos_users_mm.finished_instance", 00914 'sys_todos', 00915 "sys_todos_users_mm", 00916 '', 00917 " AND (sys_todos_users_mm.uid_foreign=".intval($this->BE_USER->user['uid']).$groupQ.')'. // UID foreign must match the current users id OR be within the group-list of the user 00918 " AND sys_todos.deleted=0 AND sys_todos_users_mm.deleted=0". // Todo AND it's relation must not be deleted 00919 " AND ((sys_todos.finished=0 AND sys_todos_users_mm.finished_instance=0) OR sys_todos.cruser_id=".intval($this->BE_USER->user['uid']).')'. // Either the user must own his todo-item (in which case finished items are displayed) OR the item must NOT be finished (which will remove it from others lists.) 00920 $extraWhere, 00921 '', 00922 'sys_todos.deadline' ); // Sort by deadline 00923 } 00924 00931 function todos_getReviewUsers($wfUid) { 00932 $res = $GLOBALS['TYPO3_DB']->exec_SELECT_mm_query( 00933 'be_users.uid,be_users.username,be_users.realName', 00934 'sys_workflows', 00935 "sys_workflows_rvuser_mm", 00936 'be_users', 00937 t3lib_BEfunc::deleteClause('be_users').t3lib_BEfunc::deleteClause('sys_workflows').' AND sys_workflows.uid='.intval($wfUid), 00938 '', 00939 'be_users.username' ); 00940 $outARr = array(); 00941 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { 00942 $outARr[$row['uid']] = $row; 00943 } 00944 return $outARr; 00945 } 00946 00954 function todos_displayLists($todoTypes, $tUid) { 00955 // debug($todoTypes,'$todoTypes',__LINE__,__FILE__); 00956 // debug($tUid,'$tUid',__LINE__,__FILE__); 00957 00958 global $LANG; 00959 00960 $lines = array(); 00961 $ownCount = 0; 00962 00963 00964 //Header 00965 $lines[] = '<tr> 00966 <td class="bgColor5"> </td> 00967 <td class="bgColor5" width=50%><strong>'.$LANG->getLL('todos_title').':</strong></td> 00968 <td class="bgColor5" width=25%><strong>'.$LANG->getLL('todos_type').':</strong></td> 00969 <td class="bgColor5" width=25%><strong>'.$LANG->getLL('todos_deadline').':</strong></td> 00970 <td class="bgColor5"><strong>'.$LANG->getLL('todos_finished').':</strong></td> 00971 </tr>'; 00972 00973 // SELECT Incoming todos (incl. own todos): 00974 // Incoming todos are those set for a user which he must carry out. Those are the relations in sys_todos_users_mm where uid_foreign is either the users uid or the negative uid of a group his a member of 00975 $res = $this->exec_todos_getQueryForTodoRels(); 00976 $out = ''; 00977 if ($GLOBALS['TYPO3_DB']->sql_num_rows($res)) { 00978 00979 $c = 0; 00980 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { 00981 $c++; 00982 if ($tUid == -$row['mm_uid']) { 00983 $bTb = '<B>'; 00984 $bTe = '</B>'; 00985 $active = '<img src="'.$this->backPath.'gfx/content_client.gif" width="7" height="10" border="0" align=top>'; 00986 } else { 00987 $bTb = $bTe = ''; 00988 $active = ''; 00989 } 00990 $t_dL = $this->dateTimeAge($row['deadline'], -1); 00991 $t_dL = ($row['deadline'] > time()) ? $t_dL : 00992 '<span class="typo3-red">'.$t_dL.'</span>'; 00993 $iconName = 'tc_todos'.($row['cruser_id'] == $this->BE_USER->user['uid']?'':'_foreign').($row['uid_foreign'] >= 0?'':'_group').'.gif'; 00994 $bgColorClass = ($c+1)%2 ? 'bgColor' : 00995 'bgColor-10'; 00996 $lines[] = '<tr> 00997 <td class="'.$bgColorClass.'">'.$this->linkTodos('<img src="'.$this->backPath.'gfx/i/'.$iconName.'" width="18" height="16" hspace=2 border=0 title="'.$LANG->getLL('todos_instance').' #'.$row['mm_uid'].', '.htmlspecialchars($LANG->getLL('todos_createdBy').': '.$this->userGroupArray[2][$row['cruser_id']]['username'].' ('.$this->userGroupArray[2][$row['cruser_id']]['realName'].')').'">', -$row['mm_uid']).'</td> 00998 <td class="'.$bgColorClass.'" nowrap>'.$this->linkTodos($active.$bTb.' '.$this->fixed_lgd($row['title']).' '.$bTb, -$row['mm_uid']).'</td> 00999 <td class="'.$bgColorClass.'" nowrap> '.t3lib_div::fixed_lgd($this->todos_workflowTitle($todoTypes, $row['type']), 15).' </td> 01000 <td class="'.$bgColorClass.'" nowrap>'.$t_dL.' </td> 01001 <td class="'.$bgColorClass.'" align=right>'.($row['cruser_id'] == $this->BE_USER->user['uid']?'<input type="hidden" name="DONE['.-$row['mm_uid'].']" value=0><input type="checkbox" name="DONE['.-$row['mm_uid'].']" value="1"'.($row['finished_instance']?" checked":"").'>':' ').'</td> 01002 </tr>'; 01003 01004 if ($row['cruser_id'] == $this->BE_USER->user['uid']) $ownCount++; 01005 } 01006 } 01007 01008 01009 01010 // SELECT Master todos for list: 01011 // A master todo is an OUTGOING todo you have created, in this case for other users. 01012 $res = $GLOBALS['TYPO3_DB']->exec_SELECT_mm_query( 01013 'sys_todos.*,sys_todos_users_mm.uid_foreign', 01014 'sys_todos', 01015 "sys_todos_users_mm", 01016 '', 01017 " AND sys_todos_users_mm.uid_foreign!=".intval($this->BE_USER->user['uid']). ' AND sys_todos.cruser_id='.intval($this->BE_USER->user['uid']). " AND sys_todos.deleted=0", 01018 'sys_todos.uid', 01019 'sys_todos.deadline' ); 01020 $out = ''; 01021 if ($GLOBALS['TYPO3_DB']->sql_num_rows($res)) { 01022 01023 $lines[] = '<tr><td colspan=5> </td></tr>'; 01024 $lines[] = '<tr> 01025 <td class="bgColor5"> </td> 01026 <td class="bgColor5" colspan="4"><strong>'.$LANG->getLL('todos_list_master').':</strong></td> 01027 </tr>'; 01028 01029 $c = 0; 01030 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { 01031 $c++; 01032 $bgColorClass = ($c+1)%2 ? 'bgColor' : 01033 'bgColor-10'; 01034 if ($tUid == $row['uid']) { 01035 $bTb = '<B>'; 01036 $bTe = '</B>'; 01037 $active = '<img src="'.$this->backPath.'gfx/content_client.gif" width="7" height="10" border="0" align=top>'; 01038 } else { 01039 $bTb = $bTe = ''; 01040 $active = ''; 01041 } 01042 $t_dL = $this->dateTimeAge($row['deadline'], -1); 01043 $t_dL = ($row['deadline'] > time()) ? $t_dL : 01044 '<span class="typo3-red">'.$t_dL.'</span>'; 01045 $iconName = 'tc_todos'.($row['uid_foreign'] >= 0?'':'_group').'.gif'; 01046 $bgColorClass = ($c+1)%2 ? 'bgColor' : 01047 'bgColor-10'; 01048 $lines[] = '<tr> 01049 <td class="'.$bgColorClass.'">'.$this->linkTodos('<img src="'.$this->backPath.'gfx/i/'.$iconName.'" width="18" height="16" hspace=2 border=0 title="'.$LANG->getLL('todos_item').' #'.$row['uid'].', '.htmlspecialchars($LANG->getLL('todos_createdBy').': '.$this->userGroupArray[2][$row['cruser_id']]['username'].' ('.$this->userGroupArray[2][$row['cruser_id']]['realName'].')').'">', $row['uid']).'</td> 01050 <td class="'.$bgColorClass.'" nowrap>'.$this->linkTodos($active.$bTb.' '.$this->fixed_lgd($row['title']).' '.$bTb, $row['uid']).'</td> 01051 <td class="'.$bgColorClass.'" nowrap> '.t3lib_div::fixed_lgd($this->todos_workflowTitle($todoTypes, $row['type']), 15).' </td> 01052 <td class="'.$bgColorClass.'" nowrap>'.$t_dL.' </td> 01053 <td class="'.$bgColorClass.'" align=right>'.($row['cruser_id'] == $this->BE_USER->user['uid']?'<input type="hidden" name="DONE['.$row['uid'].']" value=0><input type="checkbox" name="DONE['.$row['uid'].']" value="1"'.($row['finished']?" checked":"").'>':' ').'</td> 01054 </tr>'; 01055 01056 if ($row['cruser_id'] == $this->BE_USER->user['uid']) $ownCount++; 01057 } 01058 01059 // $out = '<table border=0 cellpadding=0 cellspacing=0>'.implode('',$lines).'</table>'; 01060 // $theCode.= $this->pObj->doc->spacer(10); 01061 // $theCode.= $this->pObj->doc->section($LANG->getLL('todos_list_master'),$out,1,0); 01062 } 01063 01064 if (count($lines) > 1) { 01065 $out = '<table border=0 cellpadding=0 cellspacing=0>'.implode('', $lines).'</table>'; 01066 01067 if ($ownCount) { 01068 $bMenu = '<BR><div align=right><select name="marked_todos_action"> 01069 <option value=-1></option> 01070 <option value=127>'.$LANG->getLL('todos_purge').'</option> 01071 </select><input type="submit" name="marked_todos" value="'.$LANG->getLL('todos_updateMarked').'"></div>'; 01072 } 01073 else $bMenu = ''; 01074 01075 01076 $theCode .= $this->pObj->doc->section($LANG->getLL('todos_list'), $out.$bMenu, 0, 1); 01077 } 01078 return $theCode; 01079 } 01080 01090 function todos_createForm($todoTypes, $editRec = '') { 01091 global $LANG; 01092 01093 // CREATE/EDIT/VIEW TODO: 01094 $wF = is_array($editRec) ? $editRec['type'] : 01095 t3lib_div::_GP('workflow_type'); 01096 01097 if ($wF && isset($todoTypes[$wF])) { 01098 $type = is_array($editRec) ? $editRec['uid'] : 01099 "NEW"; 01100 $formA = array(); 01101 01102 if (!is_array($editRec)) { 01103 // Making the target_user/group selector: 01104 if ($wF == 'plain') { 01105 // If the type is plain, the todo-item may be assigned to all users accessible for the current user. 01106 // Title selector: 01107 $formA[] = array($LANG->getLL('todos_type').": ", $LANG->getLL('todos_plain')); 01108 $formA[] = $this->tasks_makeTargetSelector($this->userGroupArray[0], $this->userGroupArray[1], $type); 01109 01110 } elseif (substr($wF, 0, 3) == "wf_" && $this->workflowExtIsLoaded) { 01111 // If it's a workflow from sys_workflows table, the list of target groups and users is re-fetched, according the the target_groups definition. 01112 $workflowRecord = t3lib_BEfunc::getRecord('sys_workflows', substr($wF, 3)); 01113 debug($workflowRecord, '$workflowRecord', __LINE__, __FILE__); 01114 01115 if (is_array($workflowRecord) && $workflowRecord['tablename']) { 01116 $formA[] = array($LANG->getLL('todos_type').": ", $workflowRecord['title']); 01117 // Get groupnames for todo-tasks 01118 01119 $grL = implode(',', t3lib_div::intExplode(',', $workflowRecord['target_groups'])); 01120 $wf_groupArray = t3lib_BEfunc::getGroupNames('title,uid', "AND uid IN (".($grL?$grL:0).')'); 01121 $wf_groupArrayUids = array_keys($wf_groupArray); 01122 $wf_userArray = t3lib_BEfunc::blindUserNames($this->userGroupArray[2], $wf_groupArrayUids, 1); 01123 $formA[] = $this->tasks_makeTargetSelector($wf_userArray, $wf_groupArray, $type); 01124 } 01125 } 01126 } 01127 01128 // Title selector: 01129 $formA[] = array($LANG->getLL('todos_title').": ", '<input type="text" name="data[sys_todos]['.$type.'][title]" value="'.htmlspecialchars(is_array($editRec)?$editRec['title']:$todoTypes[$wF]).'" max=255'.$this->pObj->doc->formWidth(40).'>'); 01130 01131 // Deadline selector: 01132 $curTodoTime = time(); 01133 $formA[] = array($LANG->getLL('todos_deadline').": ", '<input type="text" name="data[sys_todos]['.$type.'][deadline]_hr'.'" onChange="typo3FormFieldGet(\'data[sys_todos]['.$type.'][deadline]\', \'datetime\', \'\', 0,0);"'.$this->pObj->doc->formWidth(20).'> 01134 <input type="hidden" value="'.intval($editRec['deadline']).'" name="data[sys_todos]['.$type.'][deadline]"> 01135 <select name="_time_selector" onChange=" 01136 document.forms[0][\'data[sys_todos]['.$type.'][deadline]\'].value=(this.options[this.selectedIndex].value>0?this.options[this.selectedIndex].value:(document.forms[0][\'data[sys_todos]['.$type.'][deadline]\'].value!=\'0\'?document.forms[0][\'data[sys_todos]['.$type.'][deadline]\'].value:'.time().')-this.options[this.selectedIndex].value); 01137 this.selectedIndex=0; 01138 typo3FormFieldSet(\'data[sys_todos]['.$type.'][deadline]\', \'datetime\', \'\', 0,0); 01139 "> 01140 <option value="0"></option> 01141 <option value="'.(mktime(0, 0, 0)+3600 * 12).'">'.$LANG->getLL('todos_DL_today').'</option> 01142 <option value="'.(mktime(0, 0, 0)+3600 * 24+3600 * 12).'">'.$LANG->getLL('todos_DL_tomorrow').'</option> 01143 <option value="'.(mktime(0, 0, 0)+3600 * 24 * 7+3600 * 12).'">'.$LANG->getLL('todos_DL_weekLater').'</option> 01144 <option value="'.(mktime(0, 0, 0)+3600 * 24 * 31+3600 * 12).'">'.$LANG->getLL('todos_DL_monthLater').'</option> 01145 <option value="'.(-3600 * 24 * 1).'">+1 '.$LANG->getLL('todos_DL_day').'</option> 01146 <option value="'.(-3600 * 24 * 2).'">+2 '.$LANG->getLL('todos_DL_days').'</option> 01147 <option value="'.(-3600 * 24 * 4).'">+4 '.$LANG->getLL('todos_DL_days').'</option> 01148 <option value="'.(-3600 * 24 * 7).'">+7 '.$LANG->getLL('todos_DL_days').'</option> 01149 <option value="'.(-3600 * 24 * 14).'">+14 '.$LANG->getLL('todos_DL_days').'</option> 01150 <option value="'.(-3600 * 24 * 31).'">+31 '.$LANG->getLL('todos_DL_days').'</option> 01151 </select> 01152 '); 01153 01154 $t3lib_TCEforms = t3lib_div::makeInstance('t3lib_TCEforms'); 01155 $t3lib_TCEforms->backPath = $this->backPath; 01156 01157 $t3lib_TCEforms->extJSCODE .= 'typo3FormFieldSet("data[sys_todos]['.$type.'][deadline]", \'datetime\', "", 0,0);'; 01158 01159 // Description: 01160 $formA[] = array($LANG->getLL('todos_description').": ", '<textarea rows="10" name="data[sys_todos]['.$type.'][description]"'.$this->pObj->doc->formWidthText(40, '', '').'>'.t3lib_div::formatForTextarea(is_array($editRec)?$editRec['description']:"").'</textarea>'); 01161 01162 // Notify email: 01163 if (!is_array($editRec) && $this->BE_USER->user['email']) { 01164 $formA[] = array(' ', '<input type="checkbox" name="sendAsEmail" value=1>'.$LANG->getLL('todo_email').'<BR>('.$LANG->getLL('lReplyAddress').': '.$this->BE_USER->user['email'].')'); 01165 } 01166 01167 $formA[] = array(' ', ' '); 01168 $onClick = "if (document.forms[0]['data[sys_todos][".$type."][title]'].value=='') {alert(".$GLOBALS['LANG']->JScharCode($LANG->getLL('todos_mustFillIn')).');return false;}'; 01169 $hidden = '<input type=hidden name="data[sys_todos]['.$type.'][type]" value="'.htmlspecialchars($wF).'">'; 01170 if ($type == 'NEW') { 01171 $formA[] = array(' ', '<input type="submit" name="create_todo" value="'.$LANG->getLL('lCreate').'" onClick="'.$onClick.'"> <input type="submit" value="'.$LANG->getLL('lCancel').'">'); 01172 } else { 01173 $formA[] = array(' ', '<input type="submit" name="create_todo" value="'.$LANG->getLL('lUpdate').'"><input type="hidden" name="sys_todos_uid" value="'.$editRec['uid'].'">'); 01174 } 01175 01176 $theCode .= $this->pObj->doc->spacer(20); 01177 $theCode .= $this->pObj->doc->section('<a name="new"></a>'.$LANG->getLL(is_array($editRec)?"todos_update":"todos_new", 1), $this->pObj->doc->table($formA).$hidden.$t3lib_TCEforms->JSbottom(), 0,!is_array($editRec), 0, 1); 01178 } else { 01179 // Todo type: 01180 $opt_type = array(); 01181 reset($todoTypes); 01182 $opt_type[] = '<option value="0"></option>'; 01183 while (list($uid, $title) = each($todoTypes)) { 01184 $opt_type[] = '<option value="'.$uid.'">'.htmlspecialchars($title).'</option>'; 01185 } 01186 // $type_onChange="if (document.forms[0]['data[sys_todos][".$type."][title]'].value=='') document.forms[0]['data[sys_todos][".$type."][title]'].value=document.forms[0]['data[sys_todos][".$type."][type]'].options[document.forms[0]['data[sys_todos][".$type."][type]'].selectedIndex].text;"; 01187 $formA = array(); 01188 $formA[] = array($LANG->getLL('todos_type').": ", '<select name="workflow_type" onChange="document.location=\'index.php?workflow_type=\'+this.options[this.selectedIndex].value+\'#new\';">'.implode('', $opt_type).'</select>'); 01189 $theCode .= $this->pObj->doc->spacer(20); 01190 $theCode .= $this->pObj->doc->section($LANG->getLL('todos_new'), $this->pObj->doc->table($formA), 0, 1); 01191 } 01192 return $theCode; 01193 } 01194 01202 function linkTodos($str, $id) { 01203 $str = '<a href="index.php?sys_todos_uid='.$id.'#todo">'.$str.'</a>'; 01204 return $str; 01205 } 01206 01213 function getEditRedirectUrlForReference($recRef) { 01214 $parts = explode(':', $recRef); 01215 if ($parts[0] == 'pages') { 01216 # $outUrl = $this->backPath.'sysext/cms/layout/db_layout.php?id='.$parts[1].'&SET[function]=0&edit_record='.$parts[0].':'.$parts[1].'&returnUrl='.rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI')); 01217 $outUrl = $this->backPath.'sysext/cms/layout/db_layout.php?id='.$parts[1].'&SET[function]=1'."&returnUrl=".rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI')); 01218 } else { 01219 $outUrl = $this->backPath.'alt_doc.php?returnUrl='.rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI')).'&edit['.$parts[0].']['.$parts[1].']=edit'; 01220 } 01221 return $outUrl; 01222 } 01223 01231 function printUserGroupName($uid, $icon = 0) { 01232 if ($uid > 0) { 01233 return ($icon?t3lib_iconWorks::getIconImage('be_users', t3lib_BEfunc::getRecord('be_users', $uid), $this->backPath, $params = ' align=top'):""). $this->userGroupArray[2][$uid]['username'].($this->userGroupArray[2][$uid]['realName']?" (".$this->userGroupArray[2][$uid]['realName'].")":""); 01234 } else { 01235 $grRec = t3lib_BEfunc::getRecord('be_groups', abs($uid)); 01236 return ($icon?t3lib_iconWorks::getIconImage('be_groups', $grRec, $this->backPath, ' align="top"'):''). $grRec['title']; 01237 } 01238 } 01239 } 01240 01241 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/sys_todos/class.tx_systodos.php']) { 01242 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/sys_todos/class.tx_systodos.php']); 01243 } 01244 01245 ?>