aboutsummaryrefslogtreecommitdiff
path: root/mod/defaultwidgets/actions/update.php
blob: 466bae5a639e075f9aeb2859d70261ad5721b36f (plain)
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
<?php
/**
 * Elgg default_widgets plugin.
 *
 * @package DefaultWidgets
 * 
 **/

// validate user is an admin
admin_gatekeeper ();

// get parameters
$context = get_input ( 'context' );
$leftbar = str_replace ( '::0', '', get_input ( 'debugField1' ) );
$middlebar = str_replace ( '::0', '', get_input ( 'debugField2' ) );
$rightbar = str_replace ( '::0', '', get_input ( 'debugField3' ) );

// make sure enough parameters are set
if ($context && isset ( $leftbar ) && isset ( $middlebar ) && isset ( $rightbar )) {
	
	// join widgets into a single string
	$widgets = $leftbar . '%%' . $middlebar . '%%' . $rightbar;
	
	// get the elgg object that contains our settings
	$entities = elgg_get_entities (array('type' => 'object', 'subtype' => 'moddefaultwidgets', 'limit' => 9999));
	
	// create new object unless one already exists
	if (! isset ( $entities [0] )) {
		$entity = new ElggObject ( );
		$entity->subtype = 'moddefaultwidgets';
		$entity->owner_guid = $_SESSION ['user']->getGUID ();
	} else {
		$entity = $entities [0];
	}
	
	// store the default widgets for each context
	$entity->$context = $widgets;
	
	// make sure this object is public.
	$entity->access_id = 2;
	
	// save the object or report error
	if ($entity->save ()) {
		system_message ( elgg_echo ( 'defaultwidgets:update:success' ) );
		$entity->state = "active";
		forward ( 'pg/admin' );
	} else {
		register_error ( elgg_echo ( 'defaultwidgets:update:failed' ) );
		forward("pg/admin/appearance/default_{$context}_widgets");
	}

} else {
	
	// report incorrect parameters error
	register_error ( elgg_echo ( 'defaultwidgets:update:noparams' ) );
	forward("pg/admin/appearance/default_{$context}_widgets");

}