Skip to content

Commit 1bd66c5

Browse files
committed
Dashboard admin tabs updates
1 parent c454af0 commit 1bd66c5

File tree

5 files changed

+181
-132
lines changed

5 files changed

+181
-132
lines changed

system/application/controllers/system.php

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,10 @@ public function dashboard() {
360360
$skip_captcha = (isset($array['zone']) && 'all-books'==$array['zone'] && $this->data['login_is_super']) ? true : false;
361361
$duplicate = (is_numeric($array['book_to_duplicate']) && !empty($array['book_to_duplicate'])) ? true : false;
362362
$skip_captcha = true;
363+
if (empty($array['title'])) {
364+
header('Location: '.$this->base_url.'?book_id='.$book_id.'&zone='.$this->data['zone'].'&error=1');
365+
exit;
366+
}
363367
try {
364368
if ($duplicate) {
365369
$book_id = (int) $this->books->duplicate($array, (($skip_captcha)?false:true));
@@ -389,11 +393,22 @@ public function dashboard() {
389393
case 'do_add_user': // Admin: All Users
390394
if (!$this->data['login_is_super']) $this->kickout();
391395
$array = $_POST;
392-
$book_title = (isset($array['book_title']) && !empty($array['book_title']) && 'title of first book (optional)'!=$array['book_title']) ? trim($array['book_title']) : null;
393-
$user_id = (int) $this->users->add($array);
394-
if (!empty($user_id) && !empty($book_title)) {
395-
$book_id = $this->books->add(array('title'=>$book_title), false); // Don't test CAPTCHA
396-
if (!empty($book_id)) $this->books->save_users($book_id, array($user_id), 'author');
396+
if (empty($array['email']) || empty($array['fullname']) || empty($array['password_1'])) {
397+
header('Location: '.$this->base_url.'?book_id='.$book_id.'&zone='.$this->data['zone'].'&error=1');
398+
exit;
399+
}
400+
if ($array['password_1'] != $array['password_2']) {
401+
header('Location: '.$this->base_url.'?book_id='.$book_id.'&zone='.$this->data['zone'].'&error=2');
402+
exit;
403+
}
404+
try {
405+
$array['password'] = $array['password_1'];
406+
unset($array['password_1']);
407+
unset($array['password_2']);
408+
$user_id = (int) $this->users->add($array);
409+
} catch (Exception $e) {
410+
header('Location: '.$this->base_url.'?book_id='.$book_id.'&zone='.$this->data['zone'].'&error=3');
411+
exit;
397412
}
398413
header('Location: '.$this->base_url.'?book_id='.$book_id.'&zone='.$this->data['zone'].'&action=added');
399414
exit;
@@ -427,6 +442,30 @@ public function dashboard() {
427442
if (!$this->data['login_is_super']) $this->kickout();
428443
$this->data['recent_book_list'] = $this->books->get_all_with_creator(0, false,'created','desc',500);
429444
break;
445+
case 'do_delete_users': // Admin: Tools > List recently created users
446+
if (!$this->data['login_is_super']) $this->kickout();
447+
$zone = $this->data['zone'];
448+
$user_ids = explode(',',$_REQUEST['user_ids']);
449+
$delete_books = (1==(int)$_REQUEST['delete_books']) ? true : false;
450+
foreach ($user_ids as $user_id) {
451+
$user_id = (int) $user_id;
452+
if (empty($user_id)) continue;
453+
$user = $this->users->get_by_user_id($user_id);
454+
if (empty($user)) continue;
455+
if ($delete_books) {
456+
$books = $this->users->get_books($user_id);
457+
foreach ($books as $book) {
458+
if (!$this->users->is_a($book->relationship, 'author')) continue;
459+
$this->books->delete($book->book_id);
460+
}
461+
}
462+
$this->users->delete($user_id);
463+
}
464+
// Don't bresk
465+
case "get_recent_users": // Admin: Tools
466+
if (!$this->data['login_is_super']) $this->kickout();
467+
$this->data['recent_user_list'] = $this->users->get_all(0, true, 'user_id', 'desc',500);
468+
break;
430469
case "get_email_list": // Admin: Tools
431470
if (!$this->data['login_is_super']) $this->kickout();
432471
$users = $this->users->get_all();
@@ -468,6 +507,7 @@ public function dashboard() {
468507
$this->data['book'] = ($book_id) ? $this->books->get($book_id) : array();
469508
$this->data['title'] = (!empty($this->data['book'])) ? $this->data['book']->title.' Dashboard' : $this->config->item('install_name').': Dashboard';
470509
$this->data['cover_title'] = 'Dashboard';
510+
$this->data['register_key'] = $this->config->item('register_key');
471511

472512
// Get general data for each zone; this is useful for displaying red dots for "not live" content in each tab, even though it's a performance hit
473513
$this->data['current_book_users'] =
@@ -554,7 +594,6 @@ public function dashboard() {
554594
$this->data['books'] = array();
555595
}
556596
$this->data['users'] = ($this->data['login_is_super']) ? $this->users->get_all() : array();
557-
558597
break;
559598
}
560599
}

system/application/views/modules/dashboard/all-books.php

Lines changed: 40 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,8 @@
11
<?$this->template->add_js('system/application/views/modules/dashboard/jquery.dashboardtable.js')?>
2-
<? if (isset($_REQUEST['action']) && 'deleted'==$_REQUEST['action']): ?>
3-
<div class="saved">
4-
<a style="float:right;" href="?zone=all-books#tabs-all-books">clear</a>
5-
Book has been deleted
6-
</div><br />
7-
<? endif ?>
8-
<? if (isset($_REQUEST['action']) && 'added'==$_REQUEST['action']): ?>
9-
<div class="saved">
10-
<a style="float:right;" href="?zone=all-books#tabs-all-books">clear</a>
11-
Book has been added
12-
</div><br />
13-
<? endif ?>
2+
143
<style>
154
.admin-nav-wrap {
16-
margin:7px 0;
17-
float:left;
5+
margin:12px 0px 0px 0px;
186
width:100%;
197
}
208
.book-search-form {
@@ -52,8 +40,9 @@
5240
var rel = $this.attr('rel');
5341
var id = $this.parents('tr').find("td[property='id']").html();
5442
var ids = new Array;
55-
var elements = $this.parent().find("span");
43+
var elements = $this.closest('td').find("span");
5644
for (var j = 0; j < elements.length; j++) {
45+
if (!$(elements[j]).attr('id')) continue;
5746
ids.push( $(elements[j]).attr('id') );
5847
}
5948
var post = {'id':id};
@@ -67,13 +56,13 @@
6756
$.post('api/'+resource, post, function(data) {
6857
selector.html('');
6958
var option = $('<option value="0">(Select none)</option>');
70-
selector.append(option);
7159
for (var j = 0; j < data.length; j++) {
7260
var rel_id = data[j].user_id;
7361
if ('undefined'==typeof(rel_id)) rel_id = data[j].book_id;
7462
var title = data[j].fullname;
7563
if ('undefined'==typeof(title)) title = data[j].title;
7664
var selected = (ids.indexOf(rel_id) != -1) ? true : false;
65+
console.log(ids);
7766
var option = $('<option value="'+rel_id+'"'+((selected)?' selected':'')+'>'+title+'</option>');
7867
selector.append(option);
7968
}
@@ -124,52 +113,37 @@ function submit_value_selector($this) {
124113
}
125114
</script>
126115

127-
<form style="display:inline-block" action="<?=confirm_slash(base_url())?>system/dashboard#tabs-all-books" method="post">
116+
<? if (isset($_GET['error']) && $_GET['error']==1): ?>
117+
<div class="error" style="max-width:none; margin-bottom:16px;">Title is a required field<a style="float:right;" href="?book_id=<?=((isset($book->book_id))?$book->book_id:0)?>&zone=all-books#tabs-all-books">clear</a></div>
118+
<? endif; ?>
119+
<? if (isset($_REQUEST['action']) && 'deleted'==$_REQUEST['action']): ?>
120+
<div class="saved" style="max-width:none; margin-bottom:16px;">
121+
<a style="float:right;" href="?zone=all-books#tabs-all-books">clear</a>
122+
Book has been deleted
123+
</div>
124+
<? endif ?>
125+
<? if (isset($_REQUEST['action']) && 'added'==$_REQUEST['action']): ?>
126+
<div class="saved" style="max-width:none; margin-bottom:16px;">
127+
<a style="float:right;" href="?zone=all-books#tabs-all-books">clear</a>
128+
Book has been added and is present in the list below
129+
</div>
130+
<? endif ?>
131+
132+
<form style="margin:10px 0px 18px 0px; white-space:nowrap;" action="<?=confirm_slash(base_url())?>system/dashboard#tabs-all-books" method="post">
128133
<input type="hidden" name="zone" value="all-books" />
129134
<input type="hidden" name="action" value="do_add_book" />
130-
Add new book: <input type="text" name="title" value="title" style="width:200px;" onfocus="if (this.value=='title') this.value='';" />&nbsp;
131-
<select name="user_id">
132-
<option value="0">(Initial author)</option>
135+
<span style="float:left; margin-right:6px;">Add new book:</span>
136+
<input type="text" name="title" value="" placeholder="Title" style="width:200px;float:left;" />
137+
<input type="text" name="subtitle" value="" placeholder="Subtitle" style="width:200px;float:left;margin-left:8px;" />
138+
<select name="user_id" style="font-size:12px; float:left; margin-left:8px; margin-right:8px; padding-top:1px; padding-bottom:0px;">
139+
<option value="0">Initial author</option>
133140
<? foreach ($users as $user): ?>
134141
<option value="<?=$user->user_id?>"><?=$user->fullname?></option>
135142
<? endforeach ?>
136-
</select>&nbsp;
137-
<input type="submit" value="Go" class="generic_button" />
138-
</form>
139-
<div class="admin-nav-wrap">
140-
<? if (!empty($books)): ?>
141-
<?
142-
if((count($books)-1) != $total)
143-
$count = count($books);
144-
else
145-
$count = count($books)-1;
146-
?>
147-
<? if ($start !== 0 || (count($books)-1) == $total): ?>
148-
<? if($start !== 0): ?>
149-
<span class="prev"><a href="<?=confirm_slash(base_url())?>system/dashboard?zone=all-books&amp;start=<?=$start-$total?>&amp;total=<?=$total?>#tabs-all-books">Prev page</a></span>
150-
&nbsp;
151-
<? endif ?>
152-
<b class="total"><?=$start+1?> - <?=$start + $count?></b>
153-
<? if(count($books)-1 == $total): ?>
154-
&nbsp; <span class="next"><a href="<?=confirm_slash(base_url())?>system/dashboard?zone=all-books&amp;start=<?=$start+$total?>&amp;total=<?=$total?>#tabs-all-books">Next page</a></span>
155-
<? endif ?>
156-
<form style="display:inline-block" class="jump-form">
157-
<span>&nbsp;&nbsp;&nbsp;&nbsp;Go to page:</span>
158-
<input style="text-align:right" placeholder="<?=$start/$total+1?>" type="text" class="jump-to-page" size="2" />
159-
</form>
160-
&nbsp; &nbsp; &nbsp; &nbsp;
161-
<? endif ?>
162-
<? endif ?>
163-
<form class="book-search-form">
164-
<input placeholder="Find Book" type="text" class="book-search" size="20" />
165-
<input style="vertical-align:bottom;" type="submit" value="Search" class="generic_button" />
166-
<?=(isset($_REQUEST['id']) && is_numeric($_REQUEST['id'])) ? ' &nbsp; Showing book ID '.$_REQUEST['id'].' &nbsp; ' : ''?>
167-
<a href="<?=confirm_slash(base_url())?>system/dashboard?zone=all-books&amp;start=<?=$start?>&amp;total=<?=$total?>#tabs-all-books">clear</a>
168-
</form>
169-
</div>
170-
171-
143+
</select>
144+
<input type="submit" value="Add" style="padding:3px 8px 1px 8px !important; float:left;" class="generic_button default" />
172145
<br clear="both" />
146+
</form>
173147

174148
<div class="table_wrapper">
175149
<table cellspacing="0" cellpadding="0" class="tablesorter">
@@ -192,6 +166,7 @@ function submit_value_selector($this) {
192166
<tbody>
193167
<?
194168
if (!empty($books)) {
169+
$count = count($books);
195170
for($i=0;$i<$count;$i++) {
196171
$desc_excerpt = create_excerpt($books[$i]->description);
197172
if (strlen($books[$i]->description) == strlen($desc_excerpt)) $desc_excerpt = null;
@@ -222,7 +197,7 @@ function submit_value_selector($this) {
222197
}
223198
echo '<p><a href="javascript:;" class="value_select_trigger multiple generic_button" resource="get_system_users" rel="save_book_users" style="white-space:nowrap;">Edit users</a></p>';
224199
echo "</td>\n";
225-
echo '<td style="white-space:nowrap;">'.date( 'M j, Y g:i A', strtotime($books[$i]->created) )."</td>\n";
200+
echo '<td style="white-space:nowrap;">'.date( 'M j, Y', strtotime($books[$i]->created) )."</td>\n";
226201
echo "</tr>\n";
227202
}
228203
}
@@ -231,7 +206,6 @@ function submit_value_selector($this) {
231206
</table>
232207
</div>
233208

234-
<? if (!empty($books)): ?>
235209
<div class="admin-nav-wrap">
236210
<?
237211
if((count($books)-1) != $total)
@@ -246,13 +220,18 @@ function submit_value_selector($this) {
246220
<? endif ?>
247221
<b class="total"><?=$start+1?> - <?=$start + $count?></b>
248222
<? if(count($books)-1 == $total): ?>
249-
&nbsp; <span class="prev"><a href="<?=confirm_slash(base_url())?>system/dashboard?zone=all-books&amp;start=<?=$start+$total?>&amp;total=<?=$total?>#tabs-all-books">Next page</a></span>
223+
&nbsp; <span class="next"><a href="<?=confirm_slash(base_url())?>system/dashboard?zone=all-books&amp;start=<?=$start+$total?>&amp;total=<?=$total?>#tabs-all-books">Next page</a></span>
250224
<? endif ?>
251225
<form style="display:inline-block" class="jump-form">
252226
<span>&nbsp;&nbsp;&nbsp;&nbsp;Go to page:</span>
253227
<input style="text-align:right" placeholder="<?=$start/$total+1?>" type="text" class="jump-to-page" size="2" />
254228
</form>
229+
&nbsp; &nbsp; &nbsp; &nbsp;
255230
<? endif ?>
231+
<form class="book-search-form">
232+
<input placeholder="Search for a book" type="text" class="book-search" size="20" />
233+
<input type="submit" value="Search" class="generic_button" style="padding:3px 8px 1px 8px !important; vertical-align:top;" />
234+
<?=(isset($_REQUEST['id']) && is_numeric($_REQUEST['id'])) ? ' &nbsp; Showing book ID '.$_REQUEST['id'].' &nbsp; ' : ''?>
235+
<a href="<?=confirm_slash(base_url())?>system/dashboard?zone=all-books&amp;start=<?=$start?>&amp;total=<?=$total?>#tabs-all-books">clear</a>
236+
</form>
256237
</div>
257-
<? endif ?>
258-
<br />

0 commit comments

Comments
 (0)