1<?php 2/* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org> 3 * Copyright (C) 2006-2015 Laurent Destailleur <eldy@users.sourceforge.net> 4 * Copyright (C) 2010-2012 Regis Houssin <regis.houssin@inodbox.com> 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 3 of the License, or 9 * (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program. If not, see <https://www.gnu.org/licenses/>. 18 */ 19 20/** 21 * \file htdocs/projet/tasks/contact.php 22 * \ingroup project 23 * \brief Actors of a task 24 */ 25 26require "../../main.inc.php"; 27require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; 28require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php'; 29require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; 30require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php'; 31require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; 32 33// Load translation files required by the page 34$langs->loadLangs(array('projects', 'companies')); 35 36$id = GETPOST('id', 'int'); 37$ref = GETPOST('ref', 'alpha'); 38$action = GETPOST('action', 'aZ09'); 39$confirm = GETPOST('confirm', 'alpha'); 40$withproject = GETPOST('withproject', 'int'); 41$project_ref = GETPOST('project_ref', 'alpha'); 42 43// Security check 44$socid = 0; 45//if ($user->socid > 0) $socid = $user->socid; // For external user, no check is done on company because readability is managed by public status of project and assignement. 46//$result = restrictedArea($user, 'projet', $id, 'projet_task'); 47if (!$user->rights->projet->lire) accessforbidden(); 48 49$object = new Task($db); 50$projectstatic = new Project($db); 51 52 53/* 54 * Actions 55 */ 56 57// Add new contact 58if ($action == 'addcontact' && $user->rights->projet->creer) 59{ 60 $source = 'internal'; 61 if (GETPOST("addsourceexternal")) { 62 $source ='external'; 63 } 64 65 $result = $object->fetch($id, $ref); 66 67 if ($result > 0 && $id > 0) 68 { 69 if ($source == 'internal') { 70 $idfortaskuser = ((GETPOST("userid") != 0 && GETPOST('userid') != -1) ? GETPOST("userid") : 0); // GETPOST('contactid') may val -1 to mean empty or -2 to means "everybody" 71 $typeid = GETPOST('type'); 72 } else { 73 $idfortaskuser = ((GETPOST("contactid") > 0) ? GETPOST("contactid", 'int') : 0); // GETPOST('contactid') may val -1 to mean empty or -2 to means "everybody" 74 $typeid = GETPOST('typecontact'); 75 } 76 if ($idfortaskuser == -2) 77 { 78 $result = $projectstatic->fetch($object->fk_project); 79 if ($result <= 0) 80 { 81 dol_print_error($db, $projectstatic->error, $projectstatic->errors); 82 } else { 83 $contactsofproject = $projectstatic->getListContactId('internal'); 84 foreach ($contactsofproject as $key => $val) 85 { 86 $result = $object->add_contact($val, $typeid, $source); 87 } 88 } 89 } else { 90 $result = $object->add_contact($idfortaskuser, $typeid, $source); 91 } 92 } 93 94 if ($result >= 0) { 95 header("Location: ".$_SERVER["PHP_SELF"]."?id=".$object->id.($withproject ? '&withproject=1' : '')); 96 exit; 97 } else { 98 if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') { 99 $langs->load("errors"); 100 setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors'); 101 } else { 102 setEventMessages($object->error, $object->errors, 'errors'); 103 } 104 } 105} 106 107// bascule du statut d'un contact 108if ($action == 'swapstatut' && $user->rights->projet->creer) 109{ 110 if ($object->fetch($id, $ref)) { 111 $result = $object->swapContactStatus(GETPOST('ligne')); 112 } else { 113 dol_print_error($db); 114 } 115} 116 117// Efface un contact 118if ($action == 'deleteline' && $user->rights->projet->creer) 119{ 120 $object->fetch($id, $ref); 121 $result = $object->delete_contact($_GET["lineid"]); 122 123 if ($result >= 0) 124 { 125 header("Location: ".$_SERVER["PHP_SELF"]."?id=".$object->id.($withproject ? '&withproject=1' : '')); 126 exit; 127 } else { 128 dol_print_error($db); 129 } 130} 131 132// Retrieve First Task ID of Project if withprojet is on to allow project prev next to work 133if (!empty($project_ref) && !empty($withproject)) 134{ 135 if ($projectstatic->fetch(0, $project_ref) > 0) 136 { 137 $tasksarray = $object->getTasksArray(0, 0, $projectstatic->id, $socid, 0); 138 if (count($tasksarray) > 0) 139 { 140 $id = $tasksarray[0]->id; 141 } else { 142 header("Location: ".DOL_URL_ROOT.'/projet/tasks.php?id='.$projectstatic->id.($withproject ? '&withproject=1' : '').(empty($mode) ? '' : '&mode='.$mode)); 143 exit; 144 } 145 } 146} 147 148/* 149 * View 150 */ 151 152llxHeader('', $langs->trans("Task")); 153 154$form = new Form($db); 155$formcompany = new FormCompany($db); 156$contactstatic = new Contact($db); 157$userstatic = new User($db); 158 159 160/* *************************************************************************** */ 161/* */ 162/* Mode vue et edition */ 163/* */ 164/* *************************************************************************** */ 165 166if ($id > 0 || !empty($ref)) 167{ 168 if ($object->fetch($id, $ref) > 0) 169 { 170 if (!empty($conf->global->PROJECT_ALLOW_COMMENT_ON_TASK) && method_exists($object, 'fetchComments') && empty($object->comments)) $object->fetchComments(); 171 $id = $object->id; // So when doing a search from ref, id is also set correctly. 172 173 $result = $projectstatic->fetch($object->fk_project); 174 if (!empty($conf->global->PROJECT_ALLOW_COMMENT_ON_PROJECT) && method_exists($projectstatic, 'fetchComments') && empty($projectstatic->comments)) $projectstatic->fetchComments(); 175 if (!empty($projectstatic->socid)) $projectstatic->fetch_thirdparty(); 176 177 $object->project = clone $projectstatic; 178 179 $userWrite = $projectstatic->restrictedProjectArea($user, 'write'); 180 181 if ($withproject) 182 { 183 // Tabs for project 184 $tab = 'tasks'; 185 $head = project_prepare_head($projectstatic); 186 print dol_get_fiche_head($head, $tab, $langs->trans("Project"), -1, ($projectstatic->public ? 'projectpub' : 'project')); 187 188 $param = ($mode == 'mine' ? '&mode=mine' : ''); 189 190 // Project card 191 192 $linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>'; 193 194 $morehtmlref = '<div class="refidno">'; 195 // Title 196 $morehtmlref .= $projectstatic->title; 197 // Thirdparty 198 if ($projectstatic->thirdparty->id > 0) 199 { 200 $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$projectstatic->thirdparty->getNomUrl(1, 'project'); 201 } 202 $morehtmlref .= '</div>'; 203 204 // Define a complementary filter for search of next/prev ref. 205 if (!$user->rights->projet->all->lire) 206 { 207 $objectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 0); 208 $projectstatic->next_prev_filter = " rowid in (".(count($objectsListId) ?join(',', array_keys($objectsListId)) : '0').")"; 209 } 210 211 dol_banner_tab($projectstatic, 'project_ref', $linkback, 1, 'ref', 'ref', $morehtmlref); 212 213 print '<div class="fichecenter">'; 214 print '<div class="fichehalfleft">'; 215 print '<div class="underbanner clearboth"></div>'; 216 217 print '<table class="border tableforfield centpercent">'; 218 219 // Usage 220 if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES) || empty($conf->global->PROJECT_HIDE_TASKS)) { 221 print '<tr><td class="tdtop">'; 222 print $langs->trans("Usage"); 223 print '</td>'; 224 print '<td>'; 225 if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) 226 { 227 print '<input type="checkbox" disabled name="usage_opportunity"'.(GETPOSTISSET('usage_opportunity') ? (GETPOST('usage_opportunity', 'alpha') != '' ? ' checked="checked"' : '') : ($projectstatic->usage_opportunity ? ' checked="checked"' : '')).'"> '; 228 $htmltext = $langs->trans("ProjectFollowOpportunity"); 229 print $form->textwithpicto($langs->trans("ProjectFollowOpportunity"), $htmltext); 230 print '<br>'; 231 } 232 if (empty($conf->global->PROJECT_HIDE_TASKS)) 233 { 234 print '<input type="checkbox" disabled name="usage_task"'.(GETPOSTISSET('usage_task') ? (GETPOST('usage_task', 'alpha') != '' ? ' checked="checked"' : '') : ($projectstatic->usage_task ? ' checked="checked"' : '')).'"> '; 235 $htmltext = $langs->trans("ProjectFollowTasks"); 236 print $form->textwithpicto($langs->trans("ProjectFollowTasks"), $htmltext); 237 print '<br>'; 238 } 239 if (empty($conf->global->PROJECT_HIDE_TASKS) && !empty($conf->global->PROJECT_BILL_TIME_SPENT)) 240 { 241 print '<input type="checkbox" disabled name="usage_bill_time"'.(GETPOSTISSET('usage_bill_time') ? (GETPOST('usage_bill_time', 'alpha') != '' ? ' checked="checked"' : '') : ($projectstatic->usage_bill_time ? ' checked="checked"' : '')).'"> '; 242 $htmltext = $langs->trans("ProjectBillTimeDescription"); 243 print $form->textwithpicto($langs->trans("BillTime"), $htmltext); 244 print '<br>'; 245 } 246 print '</td></tr>'; 247 } 248 249 // Visibility 250 print '<tr><td class="titlefield">'.$langs->trans("Visibility").'</td><td>'; 251 if ($projectstatic->public) print $langs->trans('SharedProject'); 252 else print $langs->trans('PrivateProject'); 253 print '</td></tr>'; 254 255 // Date start - end 256 print '<tr><td>'.$langs->trans("DateStart").' - '.$langs->trans("DateEnd").'</td><td>'; 257 $start = dol_print_date($projectstatic->date_start, 'day'); 258 print ($start ? $start : '?'); 259 $end = dol_print_date($projectstatic->date_end, 'day'); 260 print ' - '; 261 print ($end ? $end : '?'); 262 if ($projectstatic->hasDelay()) print img_warning("Late"); 263 print '</td></tr>'; 264 265 // Budget 266 print '<tr><td>'.$langs->trans("Budget").'</td><td>'; 267 if (strcmp($projectstatic->budget_amount, '')) print price($projectstatic->budget_amount, '', $langs, 1, 0, 0, $conf->currency); 268 print '</td></tr>'; 269 270 // Other attributes 271 $cols = 2; 272 //include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php'; 273 274 print '</table>'; 275 276 print '</div>'; 277 print '<div class="fichehalfright">'; 278 print '<div class="ficheaddleft">'; 279 print '<div class="underbanner clearboth"></div>'; 280 281 print '<table class="border tableforfield" width="100%">'; 282 283 // Description 284 print '<td class="titlefield tdtop">'.$langs->trans("Description").'</td><td>'; 285 print nl2br($projectstatic->description); 286 print '</td></tr>'; 287 288 // Categories 289 if ($conf->categorie->enabled) { 290 print '<tr><td class="valignmiddle">'.$langs->trans("Categories").'</td><td>'; 291 print $form->showCategories($projectstatic->id, 'project', 1); 292 print "</td></tr>"; 293 } 294 295 print '</table>'; 296 297 print '</div>'; 298 print '</div>'; 299 print '</div>'; 300 301 print '<div class="clearboth"></div>'; 302 303 print dol_get_fiche_end(); 304 305 print '<br>'; 306 } 307 308 309 // To verify role of users 310 //$userAccess = $projectstatic->restrictedProjectArea($user); // We allow task affected to user even if a not allowed project 311 //$arrayofuseridoftask=$object->getListContactId('internal'); 312 313 $head = task_prepare_head($object); 314 print dol_get_fiche_head($head, 'task_contact', $langs->trans("Task"), -1, 'projecttask', 0, '', 'reposition'); 315 316 317 $param = (GETPOST('withproject') ? '&withproject=1' : ''); 318 $linkback = GETPOST('withproject') ? '<a href="'.DOL_URL_ROOT.'/projet/tasks.php?id='.$projectstatic->id.'">'.$langs->trans("BackToList").'</a>' : ''; 319 320 if (!GETPOST('withproject') || empty($projectstatic->id)) 321 { 322 $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1); 323 $object->next_prev_filter = " fk_projet in (".$projectsListId.")"; 324 } else $object->next_prev_filter = " fk_projet = ".$projectstatic->id; 325 326 $morehtmlref = ''; 327 328 // Project 329 if (empty($withproject)) 330 { 331 $result = $projectstatic->fetch($object->fk_project); 332 $morehtmlref .= '<div class="refidno">'; 333 $morehtmlref .= $langs->trans("Project").': '; 334 $morehtmlref .= $projectstatic->getNomUrl(1); 335 $morehtmlref .= '<br>'; 336 337 // Third party 338 $morehtmlref .= $langs->trans("ThirdParty").': '; 339 if ($projectstatic->socid > 0) { 340 $projectstatic->fetch_thirdparty(); 341 $morehtmlref .= $projectstatic->thirdparty->getNomUrl(1); 342 } 343 344 $morehtmlref .= '</div>'; 345 } 346 347 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, $param, 0, '', '', 1); 348 349 print dol_get_fiche_end(); 350 351 /* 352 * Lines of contacts 353 */ 354 /* 355 // Contacts lines (modules that overwrite templates must declare this into descriptor) 356 $dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl')); 357 foreach($dirtpls as $reldir) 358 { 359 $res=@include dol_buildpath($reldir.'/contacts.tpl.php'); 360 if ($res) break; 361 } 362 */ 363 364 /* 365 * Add a new contact line 366 */ 367 print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$id.'" method="POST">'; 368 print '<input type="hidden" name="token" value="'.newToken().'">'; 369 print '<input type="hidden" name="action" value="addcontact">'; 370 print '<input type="hidden" name="id" value="'.$id.'">'; 371 if ($withproject) print '<input type="hidden" name="withproject" value="'.$withproject.'">'; 372 373 print '<table class="noborder centpercent">'; 374 375 if ($action != 'editline' && $user->rights->projet->creer) 376 { 377 print '<tr class="liste_titre">'; 378 print '<td>'.$langs->trans("NatureOfContact").'</td>'; 379 print '<td>'.$langs->trans("ThirdParty").'</td>'; 380 print '<td>'.$langs->trans("Users").'</td>'; 381 print '<td>'.$langs->trans("ContactType").'</td>'; 382 print '<td colspan="3"> </td>'; 383 print "</tr>\n"; 384 385 // Ligne ajout pour contact interne 386 print '<tr class="oddeven nohover">'; 387 388 print '<td class="nowrap">'; 389 print img_object('', 'user').' '.$langs->trans("Users"); 390 print '</td>'; 391 392 print '<td>'; 393 print $conf->global->MAIN_INFO_SOCIETE_NOM; 394 print '</td>'; 395 396 print '<td>'; 397 // On recupere les id des users deja selectionnes 398 if ($object->project->public) $contactsofproject = ''; // Everybody 399 else $contactsofproject = $projectstatic->getListContactId('internal'); 400 print $form->select_dolusers((GETPOSTISSET('userid') ? GETPOST('userid', 'int') : $user->id), 'userid', 0, '', 0, '', $contactsofproject, 0, 0, 0, '', 1, $langs->trans("ResourceNotAssignedToProject")); 401 print '</td>'; 402 print '<td>'; 403 $formcompany->selectTypeContact($object, '', 'type', 'internal', 'rowid'); 404 print '</td>'; 405 print '<td class="right" colspan="3" ><input type="submit" class="button" value="'.$langs->trans("Add").'" name="addsourceinternal"></td>'; 406 print '</tr>'; 407 408 // Line to add an external contact. Only if project linked to a third party. 409 if ($projectstatic->socid) 410 { 411 print '<tr class="oddeven">'; 412 413 print '<td class="nowrap">'; 414 print img_object('', 'contact').' '.$langs->trans("ThirdPartyContacts"); 415 print '</td>'; 416 417 print '<td>'; 418 $thirdpartyofproject = $projectstatic->getListContactId('thirdparty'); 419 $selectedCompany = isset($_GET["newcompany"]) ? $_GET["newcompany"] : $projectstatic->socid; 420 $selectedCompany = $formcompany->selectCompaniesForNewContact($object, 'id', $selectedCompany, 'newcompany', $thirdpartyofproject, 0, '&withproject='.$withproject); 421 print '</td>'; 422 423 print '<td>'; 424 $contactofproject = $projectstatic->getListContactId('external'); 425 print $form->selectcontacts($selectedCompany, '', 'contactid', 0, '', $contactofproject, 0, '', false, 0, 0); 426 $nbofcontacts = $form->num; 427 print '</td>'; 428 print '<td>'; 429 $formcompany->selectTypeContact($object, '', 'typecontact', 'external', 'rowid'); 430 print '</td>'; 431 print '<td class="right" colspan="3" ><input type="submit" class="button" id="add-customer-contact" name="addsourceexternal" value="'.$langs->trans("Add").'"'; 432 if (!$nbofcontacts) print ' disabled'; 433 print '></td>'; 434 print '</tr>'; 435 } 436 } 437 438 // List of contact line 439 print '<tr class="liste_titre">'; 440 print '<td>'.$langs->trans("Source").'</td>'; 441 print '<td>'.$langs->trans("ThirdParty").'</td>'; 442 print '<td>'.$langs->trans("TaskContact").'</td>'; 443 print '<td>'.$langs->trans("ContactType").'</td>'; 444 print '<td class="center">'.$langs->trans("Status").'</td>'; 445 print '<td colspan="2"> </td>'; 446 print "</tr>\n"; 447 448 $companystatic = new Societe($db); 449 450 foreach (array('internal', 'external') as $source) 451 { 452 $tab = $object->liste_contact(-1, $source); 453 454 $num = count($tab); 455 456 $i = 0; 457 while ($i < $num) 458 { 459 print '<tr class="oddeven" valign="top">'; 460 461 // Source 462 print '<td class="left">'; 463 if ($tab[$i]['source'] == 'internal') print $langs->trans("User"); 464 if ($tab[$i]['source'] == 'external') print $langs->trans("ThirdPartyContact"); 465 print '</td>'; 466 467 // Societe 468 print '<td class="left">'; 469 if ($tab[$i]['socid'] > 0) 470 { 471 $companystatic->fetch($tab[$i]['socid']); 472 print $companystatic->getNomUrl(1); 473 } 474 if ($tab[$i]['socid'] < 0) 475 { 476 print $conf->global->MAIN_INFO_SOCIETE_NOM; 477 } 478 if (!$tab[$i]['socid']) 479 { 480 print ' '; 481 } 482 print '</td>'; 483 484 // Contact 485 print '<td>'; 486 if ($tab[$i]['source'] == 'internal') 487 { 488 $userstatic->id = $tab[$i]['id']; 489 $userstatic->lastname = $tab[$i]['lastname']; 490 $userstatic->firstname = $tab[$i]['firstname']; 491 $userstatic->photo = $tab[$i]['photo']; 492 $userstatic->login = $tab[$i]['login']; 493 $userstatic->email = $tab[$i]['email']; 494 $userstatic->statut = $tab[$i]['statuscontact']; 495 496 print $userstatic->getNomUrl(-1); 497 } 498 if ($tab[$i]['source'] == 'external') 499 { 500 $contactstatic->id = $tab[$i]['id']; 501 $contactstatic->lastname = $tab[$i]['lastname']; 502 $contactstatic->firstname = $tab[$i]['firstname']; 503 $contactstatic->email = $tab[$i]['email']; 504 $contactstatic->statut = $tab[$i]['statuscontact']; 505 print $contactstatic->getNomUrl(1); 506 } 507 print '</td>'; 508 509 // Type de contact 510 print '<td>'.$tab[$i]['libelle'].'</td>'; 511 512 // Statut 513 print '<td class="center">'; 514 // Activation desativation du contact 515 if ($object->statut >= 0) print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=swapstatut&ligne='.$tab[$i]['rowid'].($withproject ? '&withproject=1' : '').'">'; 516 print $contactstatic->LibStatut($tab[$i]['status'], 3); 517 if ($object->statut >= 0) print '</a>'; 518 print '</td>'; 519 520 // Icon update et delete 521 print '<td class="center nowrap">'; 522 if ($user->rights->projet->creer) 523 { 524 print ' '; 525 print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=deleteline&token='.newToken().'&lineid='.$tab[$i]['rowid'].($withproject ? '&withproject=1' : '').'">'; 526 print img_picto($langs->trans('Unlink'), 'unlink'); 527 print '</a>'; 528 } 529 print '</td>'; 530 531 print "</tr>\n"; 532 533 $i++; 534 } 535 } 536 print "</table>"; 537 538 print "</form>"; 539 } else { 540 print "ErrorRecordNotFound"; 541 } 542} 543 544if (is_object($hookmanager)) 545{ 546 $hookmanager->initHooks(array('contacttpl')); 547 $parameters = array(); 548 $reshook = $hookmanager->executeHooks('formContactTpl', $parameters, $object, $action); 549} 550 551// End of page 552llxFooter(); 553$db->close(); 554