Permalink
Browse files

Users can be deleted

  • Loading branch information...
1 parent 9d1f33e commit 023eec37c1af6c209e0a935730c5dc271f064549 @soonick committed Dec 19, 2010
View
@@ -93,12 +93,13 @@
break;
case 'delete' :
- $deleted = Pommo_Mailing::delete($mailingIDS);
+ echo 5;
+ /*$deleted = Pommo_Mailing::delete($mailingIDS);
$logger->addMsg(Pommo::_T('Please Wait').'...');
$params = $json->encode(array('ids' => $mailingIDS));
$smarty->assign('callbackFunction','deleteMailing');
- $smarty->assign('callbackParams',$params);
+ $smarty->assign('callbackParams',$params);*/
break;
default:
View
@@ -0,0 +1,121 @@
+<?php
+/**
+ * Copyright (C) 2005, 2006, 2007, 2008 Brice Burgess <bhb@iceburg.net>
+ *
+ * This file is part of poMMo (http://www.pommo.org)
+ *
+ * poMMo is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation; either version 2, or any later version.
+ *
+ * poMMo is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with program; see the file docs/LICENSE. If not, write to the
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+/**********************************
+ INITIALIZATION METHODS
+ *********************************/
+require ('../bootstrap.php');
+require_once(Pommo::$_baseDir.'classes/Pommo_Mailing.php');
+
+Pommo::init();
+$logger = & Pommo::$_logger;
+
+
+/**********************************
+ SETUP TEMPLATE, PAGE
+ *********************************/
+require_once(Pommo::$_baseDir.'classes/Pommo_Template.php');
+$smarty = new Pommo_Template();
+
+// fetch the mailing IDs
+$mailingIDS = $_REQUEST['mailings'];
+if(!is_array($mailingIDS))
+ $mailingIDS = array($mailingIDS);
+
+
+/**********************************
+ JSON OUTPUT INITIALIZATION
+ *********************************/
+require_once(Pommo::$_baseDir.'classes/Pommo_Json.php');
+$json = new Pommo_Json(false); // do not toggle escaping
+
+// EXAMINE CALL
+switch ($_REQUEST['call']) {
+ case 'notice':
+ foreach($mailingIDS as $id) {
+ $logger->AddMsg('<br /><br />###'. sprintf(Pommo::_T('Displaying notices for mailing %s'),Pommo_Mailing::getSubject($id)).' ###<br /><br />');
+ $notices = Pommo_Mailing::getNotices($id);
+ $logger->AddMsg($notices);
+ }
+ break;
+
+ case 'reload' :
+
+ require_once(Pommo::$_baseDir.'classes/Pommo_Groups.php');
+
+ $mailing = current(Pommo_Mailing::get(array('id' => $_REQUEST['mailings'])));
+
+ // change group name to ID
+ $groups = Pommo_Groups::getNames();
+ $gid = 'all';
+ foreach($groups as $group)
+ if ($group['name'] == $mailing['group'])
+ $gid = $group['id'];
+
+ Pommo_Api::stateReset(array('mailing'));
+
+ // if this is a plain text mailing, switch body + altbody.
+ if($mailing['ishtml'] == 'off') {
+ $mailing['altbody'] = $mailing['body'];
+ $mailing['body'] = null;
+ }
+
+ // Initialize page state with default values overriden by those held in $_REQUEST
+ $state =& Pommo_Api::stateInit('mailing',array(
+ 'fromname' => $mailing['fromname'],
+ 'fromemail' => $mailing['fromemail'],
+ 'frombounce' => $mailing['frombounce'],
+ 'list_charset' => $mailing['charset'],
+ 'mailgroup' => $gid,
+ 'subject' => $mailing['subject'],
+ 'body' => $mailing['body'],
+ 'altbody' => $mailing['altbody']
+ ));
+
+ Pommo::redirect(Pommo::$_baseUrl.'mailings_start.php');
+ break;
+
+ case 'delete' :
+ $currentUser = Pommo::$_auth->_username;
+
+ // We dont want to delete the current user
+ $key = array_search($currentUser, $_GET['users']);
+ if ($key !== false)
+ {
+ unset($_GET['users'][$key]);
+ }
+
+ require_once Pommo::$_baseDir.'classes/Pommo_User.php';
+ $pu = new Pommo_User();
+ $deleted = $pu->delete($_GET['users']);
+ $logger->addMsg(Pommo::_T('Please Wait').'...');
+
+ $params = $json->encode(array('users' => $_GET['users']));
+ $smarty->assign('callbackFunction','deleteUser');
+ $smarty->assign('callbackParams',$params);
+ break;
+
+ default:
+ $logger->AddErr('invalid call');
+ break;
+}
+
+$smarty->display('admin/rpc.tpl');
+
View
@@ -162,5 +162,42 @@ function getList($data)
return false;
}
}
+
+ /* delete
+ * Deletes users from DB
+ *
+ * @param mixed $users.- String with username or array with usernames
+ *
+ * @return boolean True on success, false otherwise
+ */
+ public function delete($users)
+ {
+ try
+ {
+ if (!is_array($users))
+ {
+ $users = array($users);
+ }
+
+ $dbo = Pommo::$_dbo;
+ $dbo->_dieOnQuery = false;
+
+ $return = true;
+ foreach ($users as $user)
+ {
+ $query = 'DELETE FROM '.$dbo->table['users'].'
+ WHERE username = "%s"';
+ if (!$dbo->query($dbo->prepare($query, array($user))))
+ {
+ $return = false;
+ }
+ }
+ return $return;
+ }
+ catch(Exception $e)
+ {
+ return false;
+ }
+ }
}
View
@@ -40,4 +40,4 @@
$smarty->display('admin/setup/setup_configure.tpl');
Pommo::kill();
-?>
+
View
@@ -70,5 +70,25 @@ public function testgetList()
PHPUnit_Framework_Assert::assertEquals(3, $user->pages);
PHPUnit_Framework_Assert::assertEquals('admin07', $results[0]['username']);
}
+
+ /**
+ * @depends testsave
+ */
+ public function testdelete()
+ {
+ $user = new Pommo_User();
+
+ $user->save('admin', 'password');
+ $deleted = $user->delete('admin');
+
+ PHPUnit_Framework_Assert::assertTrue($deleted, 'Test delete user');
+
+ $user->save('admin', 'password');
+ $user->save('admin2', 'password');
+ $deleted = $user->delete(array('admin', 'admin2'));
+
+ PHPUnit_Framework_Assert::assertTrue($deleted,
+ 'Test delete multiple users');
+ }
}
@@ -50,7 +50,7 @@ $(function()
}
// serialize the data
- var data = $.param({'mailings[]': rows});
+ var data = $.param({'users[]': rows});
// rewrite the HREF of the clicked element
var oldHREF = this.href;
@@ -63,7 +63,7 @@ $(function()
}
else
{
- $('#wait').jqmShow(this);
+ $('#dialog').jqmShow(this);
}
// restore the original HREF
@@ -75,9 +75,10 @@ $(function()
});
});
-poMMo.callback.deleteMailing = function(p) {
- poMMo.grid.delRow(p.ids);
- $('#dialog').jqmHide();
+poMMo.callback.deleteUser = function(p)
+{
+ poMMo.grid.delRow(p.users);
+ $('#dialog').jqmHide();
}
</script>
@@ -88,7 +89,7 @@ poMMo.callback.deleteMailing = function(p) {
<ul class="inpage_menu">
<li>
- <a href="ajax/history.rpc.php?call=delete" class="modal confirm">
+ <a href="ajax/users.rpc.php?call=delete" class="modal confirm">
<img src="{$url.theme.shared}images/icons/delete.png"/>
{t}Delete{/t}
</a>
@@ -122,3 +123,4 @@ poMMo.callback.deleteMailing = function(p) {
<input type="submit" value="{t}Update{/t}" />
<img src="{$url.theme.shared}images/loader.gif" alt="loading..." class="hidden" name="loading" />
</form>
+
@@ -70,6 +70,7 @@ $().ready(function(){
{include file="inc/dialog.tpl" id="throttleWindow" title=$throttleTitle tall=true}
{include file="inc/dialog.tpl" id="smtpWindow" title=$smtpTitle tall=true}
{include file="inc/dialog.tpl" id="testWindow" title=$testTitle}
+{include file="inc/dialog.tpl" id=dialog wide=true tall=true}
{/capture}
{include file="inc/admin.footer.tpl"}

0 comments on commit 023eec3

Please sign in to comment.