From 94b3193fc5077c6a533c1f3ea2278a3cabc83fde Mon Sep 17 00:00:00 2001
From: Peter Rotich <peter@osticket.com>
Date: Tue, 1 Apr 2014 13:46:12 +0000
Subject: [PATCH] Add ability to delete an organization

Deleting an organization with users will simply orphaned the users.
---
 include/ajax.orgs.php                       |  3 +-
 include/class.organization.php              |  2 +-
 include/staff/templates/org-delete.tmpl.php | 56 +++++++++++++++++++++
 3 files changed, 58 insertions(+), 3 deletions(-)
 create mode 100644 include/staff/templates/org-delete.tmpl.php

diff --git a/include/ajax.orgs.php b/include/ajax.orgs.php
index 9b29f7148..def54cf3c 100644
--- a/include/ajax.orgs.php
+++ b/include/ajax.orgs.php
@@ -88,11 +88,10 @@ class OrgsAjaxAPI extends AjaxController {
         if (!$thisstaff)
             Http::response(403, 'Login Required');
         elseif (!($org = Organization::lookup($id)))
-            Http::response(404, 'Unknown user');
+            Http::response(404, 'Unknown organization');
 
         $info = array();
         if ($_SERVER['REQUEST_METHOD'] == 'DELETE') {
-
             if ($org->delete())
                  Http::response(204, 'Organization deleted successfully');
             else
diff --git a/include/class.organization.php b/include/class.organization.php
index a37665291..18b9f537d 100644
--- a/include/class.organization.php
+++ b/include/class.organization.php
@@ -124,10 +124,10 @@ class Organization extends OrganizationModel {
     }
 
     function delete() {
+        //TODO: delete  or reset intrumented list.
         return parent::delete();
     }
 
-
     function update($vars, &$errors) {
 
         $valid = true;
diff --git a/include/staff/templates/org-delete.tmpl.php b/include/staff/templates/org-delete.tmpl.php
new file mode 100644
index 000000000..17ab2bc6a
--- /dev/null
+++ b/include/staff/templates/org-delete.tmpl.php
@@ -0,0 +1,56 @@
+<?php
+
+if (!$info['title'])
+    $info['title'] = 'Delete '.Format::htmlchars($org->getName());
+
+$info['warn'] = 'Deleted organization CANNOT be recovered';
+
+?>
+<h3><?php echo $info['title']; ?></h3>
+<b><a class="close" href="#"><i class="icon-remove-circle"></i></a></b>
+<hr/>
+<?php
+
+if ($info['error']) {
+    echo sprintf('<p id="msg_error">%s</p>', $info['error']);
+} elseif ($info['warn']) {
+    echo sprintf('<p id="msg_warning">%s</p>', $info['warn']);
+} elseif ($info['msg']) {
+    echo sprintf('<p id="msg_notice">%s</p>', $info['msg']);
+} ?>
+
+<div id="org-profile" style="margin:5px;">
+    <i class="icon-group icon-4x pull-left icon-border"></i>
+    <div><b> <?php echo Format::htmlchars($org->getName()); ?></b></div>
+    <table style="margin-top: 1em;">
+<?php foreach ($org->getDynamicData() as $entry) {
+?>
+    <tr><td colspan="2" style="border-bottom: 1px dotted black"><strong><?php
+         echo $entry->getForm()->get('title'); ?></strong></td></tr>
+<?php foreach ($entry->getAnswers() as $a) { ?>
+    <tr style="vertical-align:top"><td style="width:30%;border-bottom: 1px dotted #ccc"><?php echo Format::htmlchars($a->getField()->get('label'));
+         ?>:</td>
+    <td style="border-bottom: 1px dotted #ccc"><?php echo $a->display(); ?></td>
+    </tr>
+<?php }
+}
+?>
+    </table>
+    <div class="clear"></div>
+    <hr>
+    <form method="delete" class="org"
+        action="#orgs/<?php echo $org->getId(); ?>/delete">
+        <input type="hidden" name="id" value="<?php echo $org->getId(); ?>" />
+        <p class="full-width">
+        <span class="buttons" style="float:left">
+            <input type="reset" value="Reset">
+            <input type="button" name="cancel" class="close"
+                value="No, Cancel">
+        </span>
+        <span class="buttons" style="float:right">
+            <input type="submit" value="Yes, Delete">
+        </span>
+        </p>
+    </form>
+</div>
+<div class="clear"></div>
-- 
GitLab