aboutsummaryrefslogtreecommitdiffstats
path: root/mod/manage.php
blob: 0772e2d61ff0ba772e18569fd863b82f14011be6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php

function manage_content(&$a) {

	if(! get_account_id()) {
		notice( t('Permission denied.') . EOL);
		return;
	}

	require_once('include/security.php');

	$change_channel = ((argc() > 1) ? intval(argv(1)) : 0);

	if((argc() > 2) && (argv(2) === 'default')) {
		$r = q("select channel_id from channel where channel_id = %d and channel_account_id = %d limit 1",
			intval($change_channel),
			intval(get_account_id())
		);
		if($r) {
			q("update account set account_default_channel = %d where account_id = %d limit 1",
				intval($change_channel),
				intval(get_account_id())
			);
		}
		goaway(z_root() . '/manage');
	}

	if($change_channel) {
		$r = change_channel($change_channel);

		if($r && $r['channel_startpage'])
			goaway(z_root() . '/' . $r['channel_startpage']);
		goaway(z_root());
	}

	$channels = null;

	if(local_user()) {
		$r = q("select channel.*, xchan.* from channel left join xchan on channel.channel_hash = xchan.xchan_hash where channel.channel_account_id = %d and not ( channel_pageflags & %d ) order by channel_name ",
			intval(get_account_id()),
			intval(PAGE_REMOVED)
		);

		$selected_channel = null;
		$account = get_app()->get_account();

		if($r && count($r)) {
			$channels = $r;
			for($x = 0; $x < count($channels); $x ++) {
				$channels[$x]['link'] = 'manage/' . intval($channels[$x]['channel_id']);
				if($channels[$x]['channel_id'] == local_user())
					$selected_channel = $channels[$x];
				$channels[$x]['default'] = (($channels[$x]['channel_id'] == $account['account_default_channel']) ? "1" : ''); 
				$channels[$x]['default_links'] = '1';
			}
		}
		
	    $r = q("select count(channel_id) as total from channel where channel_account_id = %d and not ( channel_pageflags & %d )",
			intval(get_account_id()),
			intval(PAGE_REMOVED)
		);
		$limit = service_class_fetch(local_user(),'total_identities');
		if($limit !== false) {
			$channel_usage_message = sprintf( t("You have created %1$.0f of %2$.0f allowed channels."), $r[0]['total'], $limit);
		}
		else {
			$channel_usage_message = '';
 		}
	}

	$links = array(
		array( 'new_channel', t('Create a new channel'), t('Create a new channel'))
	);


	$o = replace_macros(get_markup_template('channels.tpl'), array(
		'$header'           => t('Channel Manager'),
		'$msg_selected'     => t('Current Channel'),
		'$selected'         => $selected_channel,
		'$desc'             => t('Attach to one of your channels by selecting it.'),
		'$msg_default'      => t('Default Channel'),
		'$msg_make_default' => t('Make Default'),
		'$links'            => $links,
		'$all_channels'     => $channels,
		'$channel_usage_message' => $channel_usage_message,
	));


	return $o;

}