From 9a8a0ae50186208bf99fcadf87a9f8d1480261e3 Mon Sep 17 00:00:00 2001 From: Louis BAYLE Date: Sun, 1 May 2016 22:04:55 +0200 Subject: [PATCH] EditJobs: check color & set random default color + set default = assigned --- admin/edit_jobs.php | 17 +++++++++++++++-- classes/jobs.class.php | 2 +- tpl/edit_jobs.html | 5 +++-- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/admin/edit_jobs.php b/admin/edit_jobs.php index d76172a14..58229482f 100644 --- a/admin/edit_jobs.php +++ b/admin/edit_jobs.php @@ -22,12 +22,14 @@ class EditJobsController extends Controller { + private static $logger; /** * Initialize complex static variables * @static */ public static function staticInit() { // Nothing special + self::$logger = Logger::getLogger(__CLASS__); } protected function display() { @@ -37,6 +39,10 @@ protected function display() { if ($session_user->isTeamMember(Config::getInstance()->getValue(Config::id_adminTeamId))) { $this->smartyHelper->assign('jobType', Job::$typeNames); + // set random color + $rndJobColor = sprintf('%06X', mt_rand(0, 0xFFFFFF)); + $this->smartyHelper->assign('rndJobColor', $rndJobColor); + $action = Tools::getSecurePOSTStringValue('action', 'none'); if ('addJob' == $action) { @@ -46,8 +52,15 @@ protected function display() { // TODO check if not already in table ! - // save to DB - Jobs::create($job_name, $job_type, $job_color); + //Check for a hex color string without hash 'c1c2b4' + $job_color_trim = trim(str_replace("#", "", $job_color)); + if(preg_match('/^[a-f0-9]{6}$/i', $job_color_trim)) { + // save to DB + Jobs::create($job_name, $job_type, $job_color_trim); + } else { + $this->smartyHelper->assign('error', T_("Invalid Color : '$job_color' ($job_color_trim)")); + } + } elseif ('addAssociationProject' == $action) { diff --git a/classes/jobs.class.php b/classes/jobs.class.php index f1293c29c..482f2135f 100644 --- a/classes/jobs.class.php +++ b/classes/jobs.class.php @@ -26,8 +26,8 @@ class Job extends Model implements Comparable { const type_assignedJob = 1; // jobs specific to one or more projects are type 1 public static $typeNames = array( + self::type_assignedJob => "Assigned", self::type_commonJob => "Common", - self::type_assignedJob => "Assigned" ); private $id; diff --git a/tpl/edit_jobs.html b/tpl/edit_jobs.html index a71870fd5..cedd07069 100644 --- a/tpl/edit_jobs.html +++ b/tpl/edit_jobs.html @@ -9,6 +9,7 @@ {/if}
+ {if isset($jobType)}

{t}Jobs{/t}

@@ -50,7 +51,7 @@

{t}Jobs{/t}

{/foreach} - +    ColorPicker @@ -179,7 +180,7 @@

{t}Job Assignations{/t}

} } - +