public function actionConfig()
 {
     $a = Yii::app();
     list($cont, $action) = explode('/', $a->urlManager->parseUrl($a->request));
     if ('site' == $cont) {
         throw new CHttpException(403, 'Forbidden: You are not authorized to access this page.');
     }
     $path = preg_replace('/controllers/', 'config/params.php', dirname(__FILE__));
     Yii::trace("SC.actionConfig called with path {$path}", 'application.controllers.SiteController');
     $model = Parish::model()->findByPk(1);
     if (!isset($model)) {
         $model = new Parish();
     }
     $installed = Yii::app()->params['installed'];
     if (!$installed and !is_writable($path)) {
         Yii::app()->user->setFlash("error", "WARNING: the file {$path} needs to be writable before submitting this form." . "Please change the permissions of the file or, if it does not exist, of the parent config directory");
     } elseif (isset($_POST['Parish'])) {
         $model->attributes = $_POST['Parish'];
         Yii::trace("model attributes: " . var_export($model->attributes, true), 'application.controllers.SiteController');
         try {
             if (isset($_FILES['Parish'])) {
                 $files = $_FILES['Parish'];
                 $filename = $files['name']['logo'];
                 Yii::trace("IC.actionConfig called with logo {$filename}", 'application.controllers.InstallController');
                 if (isset($filename) and !empty($filename)) {
                     $tmp_path = $files['tmp_name']['logo'];
                     Yii::trace("IC.actionConfig logo temp path {$tmp_path}", 'application.controllers.InstallController');
                     if (isset($tmp_path) and !empty($tmp_path)) {
                         $dir = "images/";
                         $fname = preg_replace('/\\.[a-z]+$/i', '', $filename);
                         preg_match('/(\\.[a-z]+)$/i', $filename, $matches);
                         $fext = $matches[0];
                         if (file_exists($dir . $filename)) {
                             $fname .= "_01";
                             while (file_exists($dir . $fname . $fext)) {
                                 ++$fname;
                             }
                         }
                         $dest = $dir . $fname . $fext;
                         $parishLogo = array();
                         $parishLogo['logo_src'] = "/{$dest}";
                         list($width, $height) = getimagesize($tmp_path);
                         Yii::trace("IC.actionConfig logo dimensions {$width} x {$height}", 'application.controllers.InstallController');
                         $parishLogo['logo_width'] = $width;
                         $parishLogo['logo_height'] = $height;
                         if (is_writable($dir)) {
                             move_uploaded_file($tmp_path, $dest);
                             $model->attributes = $parishLogo;
                         } else {
                             $path = preg_replace('?protected/controllers?', $dest, dirname(__FILE__));
                             throw new Exception("Path {$path} not writable. Please ensure write permissions");
                         }
                     } else {
                         $errors = array(1 => "Size exceeds max_upload", 2 => "FORM_SIZE", 3 => "No tmp dir", 4 => "can't write", 5 => "error extension", 6 => "error partial");
                         throw new Exception($errors[$files['error']['logo']]);
                     }
                 }
             }
             if (!$installed) {
                 $params = array('installed' => true);
                 $fh = fopen($path, "r");
                 $header = "";
                 for ($i = 0; $i < 21; ++$i) {
                     if (($line = fgets($fh)) !== false) {
                         $header .= $line;
                     } else {
                         break;
                     }
                 }
                 fclose($fh);
                 $conf = $header . "return " . var_export($params, true) . ";\n";
                 file_put_contents($path, $conf);
             }
             if (!$model->save(false)) {
                 $errs = $model->errors;
                 throw new Exception("Unable to save parish data: " . $errs[0]);
             }
         } catch (Exception $e) {
             Yii::app()->user->setFlash('error', $e->getMessage());
         }
         if ("admin" != $cont) {
             $this->render("/{$cont}/success");
             return;
         } else {
             Yii::app()->user->setFlash('msg', 'Parish data saved successfully');
         }
     }
     $this->render("/{$cont}/config", array('model' => $model));
 }