require_once "api/Suggestion/Suggestion.php";
// require_once "web/includes/functions/auto_email_notify.php";
require_once "api/Messaging/MessageDispatcher.class.php";
require_once "api/Permissions/PermissionsHandler.class.php";
$authorization_required = TRUE;
//there is specific task assigned to each page
//you can see array of tasks in authorize.inc.php
/*
$page_task = 'post_to_community';//meta networks  post_to_community
require_once "web/includes/authorize.inc.php";
$permission_to_post = $task_perm;//set from authorize.inc.php
*/
$user = get_user();
$_GET = url_decode_all($_GET);
$_POST = url_decode_all($_POST);
$_REQUEST = url_decode_all($_REQUEST);
//filter_all_post($_POST);
// check to see if we are here for edit and user has permissions to do it
if ($cid = @$_REQUEST['cid']) {
    $params = array('permissions' => 'edit_content', 'uid' => PA::$login_uid, 'cid' => $cid);
    if (!PermissionsHandler::can_user(PA::$login_uid, $params)) {
        header("Location: " . PA::$url . PA_ROUTE_HOME_PAGE . "/msg=" . urlencode('Error: You are not authorized to access this page.'));
        exit;
    }
    $obj_content_type = Content::load_content((int) $cid, PA::$login_uid);
    // this content will be used for edit mode
    if ($obj_content_type->type == 'BlogPost') {
        unset($_REQUEST["sb_mc_type"]);
    }
    //tells edit mode
    $is_edit = 1;
 /** !!
  * Apply the user selected style.  If { @link $restore_style } is set to null
  * by { @link handlePOST_restoreStyle() } then PA will default to the old 
  * style.  After determining what style things are being updated too determine
  * what style is getting updated (user, group or network) and change the
  * appropriate settings.  Redirect to the same url to refresh the page when done.
  * @param string $request_data contains the from with the style information
  */
 private function handlePOST_applyStyle($request_data)
 {
     global $error, $error_msg;
     $form_data =& $request_data['form_data'];
     $form_data = url_decode_all($form_data);
     if ($this->restore_style) {
         $form_data['newcss'] = null;
         $form_data['user_json'] = null;
     }
     // clean up the JSON a bit
     $form_data['user_json'] = preg_replace("/'/", '', $form_data['user_json']);
     switch ($this->settings_type) {
         case 'user':
             $user =& $this->shared_data['user_info'];
             $user_data_ui = array('newcss' => array('name' => 'newcss', 'value' => $form_data['newcss'], 'perm' => ANYONE), 'user_json' => array('name' => 'user_json', 'value' => $form_data['user_json'], 'perm' => ANYONE));
             $user->save_profile_section($user_data_ui, 'ui');
             break;
         case 'group':
             $group =& $this->shared_data['group_info'];
             $extra =& $this->shared_data['group_extra'];
             $extra['style']['newcss'] = $form_data['newcss'];
             $extra['style']['user_json'] = $form_data['user_json'];
             $extra_param = serialize($extra);
             $ext = array('extra' => $extra_param);
             $group->save_group_theme($ext);
             break;
         case 'network':
             $network =& $this->shared_data['network_info'];
             $extra =& $this->shared_data['extra'];
             $extra['network_style'] = $form_data['newcss'];
             $extra['network_json'] = $form_data['user_json'];
             $data = array('extra' => serialize($extra), 'network_id' => $network->network_id, 'changed' => time());
             $network->set_params($data);
             try {
                 $nid = $network->save();
                 $network = get_network_info();
                 // refreshing the network info
             } catch (PAException $e) {
                 $error_msg = "{$e->message}";
             }
             unset($request_data['form_data']);
             break;
     }
     unset($request_data['form_data']);
     $this->controller->redirect($this->url);
 }