Test Failed
Push — master ( 647c72...cd42b5 )
by
unknown
10:25
created

server/includes/modules/class.settingsmodule.php (1 issue)

Severity
1
<?php
2
	/**
3
	* Settings Module
4
	*/
5
	class SettingsModule extends Module
6
	{
7
		/**
8
		* Constructor
9
		* @param int $id unique id.
10
		* @param array $data list of all actions.
11
		*/
12
		function __construct($id, $data)
13
		{
14
			parent::__construct($id, $data);
15
		}
16
17
		/**
18
		* Executes all the actions in the $data variable.
19
		* @return boolean true on success or false on fialure.
20
		*/
21
		function execute()
22
		{
23
			foreach($this->data as $actionType => $action)
24
			{
25
				if(isset($actionType)) {
26
					try {
27
						switch ($actionType) {
28
							case "retrieveAll":
29
								$this->retrieveAll($actionType);
30
								break;
31
							case "set":
32
								if ( isset($action["setting"]) ){
33
									$this->set($action["setting"], false);
34
								}
35
								if ( isset($action["persistentSetting"]) ){
36
									$this->set($action["persistentSetting"], true);
37
								}
38
								break;
39
							case "delete":
40
							case "reset":
41
								$userStore = $GLOBALS['mapisession']->getDefaultMessageStore();
42
								$inbox = mapi_msgstore_getreceivefolder($userStore);
43
								mapi_deleteprops($inbox, array(PR_ADDITIONAL_REN_ENTRYIDS_EX, PR_ADDITIONAL_REN_ENTRYIDS));
44
								$this->delete($action["setting"]);
45
								break;
46
							default:
47
								$this->handleUnknownActionType($actionType);
48
						}
49
					} catch (SettingsException $e) {
50
						$this->processException($e, $actionType);
51
					} catch (MAPIException $e) {
52
						$this->processException($e, $actionType);
53
					}
54
				}
55
			}
56
		}
57
58
		/**
59
		 * Function will retrieve all settings stored in PR_EC_WEBACCESS_SETTINGS_JSON property
60
		 * if property is not defined then it will return generate SettingsException but silently ignores it.
61
		 */
62
		function retrieveAll($type)
63
		{
64
			$data = $GLOBALS['settings']->get();
65
66
			$this->addActionData($type, $data);
67
			$GLOBALS["bus"]->addData($this->getResponseData());
68
		}
69
70
		/**
71
		 * Function will set a value of a setting indicated by path of the setting.
72
		 *
73
		 * @param $settings object/array Object containing a $path and $value of the setting
74
		 * which must be modified.
75
		 * @param $persistent boolean If true the settings will be stored in the persistent settings
76
		 * as opposed to the normal settings
77
		 */
78
		function set($settings, $persistent=false)
79
		{
80
			if (isset($settings)) {
81
				// we will set the settings but wait with saving until the entire batch has been applied.
82
				if (is_array($settings)) {
83
					foreach ($settings as $setting) {
84
						if (isset($setting['path']) && isset($setting['value'])) {
85
							if ( !!$persistent ){
86
								$GLOBALS['settings']->setPersistent($setting['path'], $setting['value']);
87
							} else {
88
								$GLOBALS['settings']->set($setting['path'], $setting['value']);
89
							}
90
						}
91
					}
92
				} else if (isset($settings['path']) && isset($settings['value'])) {
93
					if ( !!$persistent ){
94
						$GLOBALS['settings']->setPersistent($settings['path'], $settings['value']);
95
					} else {
96
						$GLOBALS['settings']->set($settings['path'], $settings['value']);
97
					}
98
				}
99
100
				// Finally save the settings, this can throw exception when it fails saving settings
101
				if ( !!$persistent ){
102
					$GLOBALS['settings']->savePersistentSettings();
103
				} else {
104
					$GLOBALS['settings']->saveSettings();
105
				}
106
107
				// send success notification to client
108
				$this->sendFeedback(true);
109
			}
110
		}
111
112
		/**
113
		 * Function will delete a setting indicated by setting path.
114
		 *
115
		 * @param $path string/array path of the setting that needs to be deleted
116
		 */
117
		function delete($path)
118
		{
119
			if(isset($path)) {
120
				// we will delete the settings but wait with saving until the entire batch has been applied.
121
				if (is_array($path)) {
122
					foreach ($path as $item) {
123
						$GLOBALS['settings']->delete($item);
124
					}
125
				} else {
126
					$GLOBALS['settings']->delete($path);
127
				}
128
129
				// Finally save the settings, this can throw exception when it fails saving settings
130
				$GLOBALS['settings']->saveSettings();
131
132
				// send success notification to client
133
				$this->sendFeedback(true);
134
			}
135
		}
136
	}
137
?>
0 ignored issues
show
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
138