Documentation TYPO3 par Ameos

class.tx_systodos.php

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


Généré par Les experts TYPO3 avec  doxygen 1.4.6