function add_ftp_connections()
 {
     /* $cus = new CustomFields();
               //$cus->initForType("Users",2);
               $flds = $cus->getCustomFieldsByType("Users");
     
               //$cus->initForType("Project",1);
               if(is_array($flds) && count($flds) > 0)
               {
               foreach ($flds as $key => $value) {
               $settings["$key"]["label"] = "Comments";
               $settings["$key"]["is_enabled"] = "1";
               $cus->setCustomFieldsByType("Users", $settings);
     
               }
               }
               print_r($flds);
               die(); */
     //$settings["label"];
     //$cus->setCustomFieldsByType("Project", $settings);
     $repo_branches = $this->active_repository;
     $eng = $repo_branches->getEngine($this->active_project->getId());
     //print_r($eng->getBranches);
     $branches_array = $eng->getBranches();
     $repo_branches_str = implode(",", $branches_array);
     $repo_id = array_var($_GET, 'project_source_repository_id');
     //project objects id
     $repo_obj = new ProjectSourceRepository($repo_id);
     $src_repo_id = $repo_obj->getIntegerField1();
     if ($this->request->isSubmitted()) {
         // check for form submission
         $post_data = $this->request->post();
         //print_r($post_data);
         try {
             $errors = new ValidationErrors();
             $ftpdetials = $post_data["ftpdetials"];
             $fld_cnt = count($ftpdetials["ftp_domain"]);
             //print_r($ftpdetials);
             //die();
             $array_urls = array();
             for ($i = 0; $i < $fld_cnt; $i++) {
                 if ($ftpdetials["ftp_domain"][$i] == "" || $ftpdetials["ftp_port"][$i] == "" || $ftpdetials["ftp_username"][$i] == "" || $ftpdetials["ftp_password"][$i] == "" || $ftpdetials["branches"][$i] == "" || $ftpdetials["ftp_dir"][$i] == "") {
                     $errors->addError("Please fill all connection parameters.");
                 } else {
                     $arra_conn[$i] = array("ftp_domain" => $ftpdetials["ftp_domain"][$i], "ftp_port" => $ftpdetials["ftp_port"][$i], "ftp_username" => $ftpdetials["ftp_username"][$i], "ftp_password" => $ftpdetials["ftp_password"][$i], "branches" => $ftpdetials["branches"][$i], "ftp_dir" => $ftpdetials["ftp_dir"][$i]);
                 }
                 /* if(!filter_var($value, FILTER_VALIDATE_URL) && $value != "")
                    {
                    $errors->addError("$value is not a valid URL.");
                    }
                    else
                    {
                    $array_urls[] = $value;
                    } */
             }
             if ($errors->hasErrors()) {
                 throw $errors;
             }
             DB::beginWork('Add FTP Details @ ' . __CLASS__);
             if (is_array($arra_conn) && count($arra_conn) > 0) {
                 $ftp_details_exists = ProjectGitolite::ftp_connections_exists($src_repo_id);
                 if (is_array($ftp_details_exists) && $ftp_details_exists["ftp_cnt"] > 0) {
                     $ftp_table_name = TABLE_PREFIX . "rt_ftp_connections";
                     DB::execute("DELETE FROM {$ftp_table_name} where repo_fk = '" . $src_repo_id . "'");
                 }
                 for ($i = 0; $i < $fld_cnt; $i++) {
                     $ftp_details_add = ProjectGitolite::add_ftp_details($arra_conn[$i], $src_repo_id, $this->logged_user->getId());
                     if (!$ftp_details_add) {
                         $errors->addError('Problem occured while saving data, please try again.');
                         throw $errors;
                     }
                 }
                 DB::commit('FTP details Added @ ' . __CLASS__);
                 $this->response->ok();
             } else {
                 $errors->addError("Error while saving FTP details.");
                 throw $errors;
             }
         } catch (Exception $e) {
             DB::rollback('Failed to add FTP details @ ' . __CLASS__);
             $this->response->exception($e);
         }
     }
     $ftp_details_exists = ProjectGitolite::get_connection_details($src_repo_id);
     $this->response->assign(array('repo_branches_str' => $repo_branches_str, 'branches_array' => $branches_array, 'ftp_test_url' => Router::assemble('test_ftp_conn', array('project_slug' => $this->active_project->getSlug(), 'project_source_repository_id' => $repo_id)), 'form_action' => Router::assemble('add_ftp_conn', array('project_slug' => $this->active_project->getSlug(), 'project_source_repository_id' => $repo_id)), "ftp_details_exists" => $ftp_details_exists));
 }