diff --git a/include/class.dept.php b/include/class.dept.php index e098e4661ce22b7728cd18f5b8f631af92ec9569..c2963219944c0e3966a08c3ee234da661037b74f 100644 --- a/include/class.dept.php +++ b/include/class.dept.php @@ -144,11 +144,32 @@ implements TemplateVariable { return !($this->flags & self::FLAG_ARCHIVED); } - function isActive() - { + function isActive() { return !!($this->flags & self::FLAG_ACTIVE); } + function clearInactiveDept($dept_id) { + global $cfg; + + $topics = Topic::objects()->filter(array('dept_id'=>$dept_id))->values_flat('topic_id'); + if ($topics) { + foreach ($topics as $topic_id) { + $topic = Topic::lookup($topic_id[0]); + $topic->dept_id = $cfg->getDefaultDeptId(); + $topic->save(); + } + } + + $emails = Email::objects()->filter(array('dept_id'=>$dept_id))->values_flat('email_id'); + if ($emails) { + foreach ($emails as $email_id) { + $email = Email::lookup($email_id[0]); + $email->dept_id = $cfg->getDefaultDeptId(); + $email->save(); + } + } + } + function getEmailId() { return $this->email_id; } diff --git a/include/class.topic.php b/include/class.topic.php index 39a03d4df76b5bf30b242b5685e5227fe7ece2d3..75aa9180664aed39d8aa64c5edb5b8774dde7fde 100644 --- a/include/class.topic.php +++ b/include/class.topic.php @@ -184,6 +184,19 @@ implements TemplateVariable { return !!($this->flags & self::FLAG_ACTIVE); } + function clearInactiveTopic($topic_id) { + global $cfg; + + $emails = Email::objects()->filter(array('topic_id'=>$topic_id))->values_flat('email_id'); + if ($emails) { + foreach ($emails as $email_id) { + $email = Email::lookup($email_id[0]); + $email->topic_id = $cfg->getDefaultTopicId(); + $email->save(); + } + } + } + function getStatus() { if($this->flags & self::FLAG_ACTIVE) return 'Active'; diff --git a/include/staff/email.inc.php b/include/staff/email.inc.php index 86ac887a0ef9e93f28c82fc5cf58bdc109c3fb18..9633acff690ca42c5aa378ea589e69460017f861 100644 --- a/include/staff/email.inc.php +++ b/include/staff/email.inc.php @@ -144,8 +144,7 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); <?php $warn = ''; $topics = Topic::getHelpTopics(); - if($info['topic_id'] && !array_key_exists($info['topic_id'], $topics)) - { + if($info['topic_id'] && !array_key_exists($info['topic_id'], $topics)) { $topics[$info['topic_id']] = $email->topic; $warn = sprintf(__('%s selected must be active'), __('Help Topic')); } diff --git a/include/staff/helptopics.inc.php b/include/staff/helptopics.inc.php index 731bee7c99d6a871d7a2a250eb5182d265649519..8978b97e36c1b94b678d006dade0a26310992949 100644 --- a/include/staff/helptopics.inc.php +++ b/include/staff/helptopics.inc.php @@ -123,13 +123,6 @@ $order_by = 'sort'; if ($topic->dept_id) { $deptId = $topic->dept_id; $dept = (string) $topic->dept; - $department = Dept::lookup($deptId); - if (!$department->isActive()) { - $deptId = $defaultDept->getId(); - $dept = (string) $defaultDept; - $topic->dept_id = $deptId; - $topic->save(); - } } elseif ($defaultDept) { $deptId = $defaultDept->getId(); $dept = (string) $defaultDept; diff --git a/scp/departments.php b/scp/departments.php index 5bb8e0dd4986d8b4d66036a85a7d2f8b46808a5c..11d03812af5bea7adeb470b9c1372d2c0c7f4b65 100644 --- a/scp/departments.php +++ b/scp/departments.php @@ -25,6 +25,9 @@ if($_REQUEST['id'] && !($dept=Dept::lookup($_REQUEST['id']))) if(!$dept){ $errors['err']=sprintf(__('%s: Unknown or invalid'), __('department')); }elseif($dept->update($_POST,$errors)){ + if ($_POST["status"] != __('Active')) + Dept::clearInactiveDept($dept->getId()); + $msg=sprintf(__('Successfully updated %s.'), __('this department')); }elseif(!$errors['err']){ @@ -96,8 +99,7 @@ if($_REQUEST['id'] && !($dept=Dept::lookup($_REQUEST['id']))) ))->exclude(array( 'id'=>$cfg->getDefaultDeptId() )); - foreach ($depts as $d) - { + foreach ($depts as $d) { $d->setFlag(Dept::FLAG_ARCHIVED, false); $d->setFlag(Dept::FLAG_ACTIVE, true); if($d->save()) @@ -122,12 +124,14 @@ if($_REQUEST['id'] && !($dept=Dept::lookup($_REQUEST['id']))) ))->exclude(array( 'id'=>$cfg->getDefaultDeptId() )); - foreach ($depts as $d) - { + foreach ($depts as $d) { $d->setFlag(Dept::FLAG_ARCHIVED, false); $d->setFlag(Dept::FLAG_ACTIVE, false); - if($d->save()) + if($d->save()) { $num++; + //set dept_id to default for topics/emails using disabled dept + Dept::clearInactiveDept($d->getId()); + } } if ($num > 0) { if($num==$count) @@ -147,12 +151,14 @@ if($_REQUEST['id'] && !($dept=Dept::lookup($_REQUEST['id']))) ))->exclude(array( 'id'=>$cfg->getDefaultDeptId() )); - foreach ($depts as $d) - { + foreach ($depts as $d) { $d->setFlag(Dept::FLAG_ARCHIVED, true); $d->setFlag(Dept::FLAG_ACTIVE, false); - if($d->save()) + if($d->save()) { $num++; + //set dept_id to default for topics/emails using archived dept + Dept::clearInactiveDept($d->getId()); + } } if ($num > 0) { if($num==$count) diff --git a/scp/helptopics.php b/scp/helptopics.php index c64a995f0faccec30add58e19940bd82a127620f..281b1c7f15391288944210d31464e4c8ceafc45b 100644 --- a/scp/helptopics.php +++ b/scp/helptopics.php @@ -28,6 +28,9 @@ if($_POST){ if(!$topic){ $errors['err']=sprintf(__('%s: Unknown or invalid'), __('help topic')); }elseif($topic->update($_POST,$errors)){ + if ($_POST["status"] != __('Active')) + Topic::clearInactiveTopic($topic->getId()); + $msg=sprintf(__('Successfully updated %s.'), __('this help topic')); }elseif(!$errors['err']){ @@ -66,8 +69,7 @@ if($_POST){ $topics = Topic::objects()->filter(array( 'topic_id__in'=>$_POST['ids'], )); - foreach ($topics as $t) - { + foreach ($topics as $t) { $t->setFlag(Topic::FLAG_ARCHIVED, false); $t->setFlag(Topic::FLAG_ACTIVE, true); if($t->save()) @@ -92,12 +94,14 @@ if($_POST){ ))->exclude(array( 'topic_id'=>$cfg->getDefaultTopicId() )); - foreach ($topics as $t) - { + foreach ($topics as $t) { $t->setFlag(Topic::FLAG_ARCHIVED, false); $t->setFlag(Topic::FLAG_ACTIVE, false); - if($t->save()) + if($t->save()) { $num++; + //remove topic_id for emails using disabled topic + Topic::clearInactiveTopic($t->getId()); + } } if ($num > 0) { if($num==$count) @@ -117,12 +121,14 @@ if($_POST){ ))->exclude(array( 'topic_id'=>$cfg->getDefaultTopicId() )); - foreach ($topics as $t) - { + foreach ($topics as $t) { $t->setFlag(Topic::FLAG_ARCHIVED, true); $t->setFlag(Topic::FLAG_ACTIVE, false); - if($t->save()) + if($t->save()) { $num++; + //remove topic_id for emails using disabled topic + Topic::clearInactiveTopic($t->getId()); + } } if ($num > 0) { if($num==$count)