src/plugins/extsubproj/NAME -text
src/plugins/extsubproj/README -text
src/plugins/extsubproj/actions/addExtSubProj.php -text
+src/plugins/extsubproj/actions/delExtSubProj.php -text
src/plugins/extsubproj/bin/db-delete.pl -text
src/plugins/extsubproj/bin/db-upgrade.pl -text
src/plugins/extsubproj/common/extsubproj-init.php -text
$confArr = array();
$confArr['newsubprojecturl'] = getStringFromRequest('newsubprojecturl');
-/*
-if (!$pluginExtSubProj->updateConf($group_id, $confArr)) {
- $error_msg = _('Failed to update configuration.');
+if (!$pluginExtSubProj->addExtSubProj($group_id, $confArr['newsubprojecturl'])) {
+ $error_msg = _('Failed to add subproject.');
session_redirect('/plugins/'.$pluginExtSubProj->name.'/?type=admin&group_id='.$group_id.'&pluginname='.$pluginExtSubProj->name.'&error_msg='.urlencode($error_msg));
}
-*/
-$feedback = _('Sub project succesfully added.').$confArr['newsubprojecturl'];
+
+$feedback = _('Sub project succesfully added.');
session_redirect('/plugins/'.$pluginExtSubProj->name.'/?type=admin&group_id='.$group_id.'&pluginname='.$pluginExtSubProj->name.'&feedback='.urlencode($feedback));
?>
--- /dev/null
+<?php
+/**
+ * Projects Hierarchy plugin
+ *
+ * Copyright 2011, Franck Villaume - Capgemini
+ * http://fusionforge.org
+ *
+ * This file is part of FusionForge. FusionForge is free software;
+ * you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software
+ * Foundation; either version 2 of the Licence, or (at your option)
+ * any later version.
+ *
+ * FusionForge is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with FusionForge; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+global $pluginExtSubProj;
+global $group_id;
+
+$url = urldecode(getStringFromRequest('url'));
+
+if (!$pluginExtSubProj->delExtSubProj($group_id, $url)) {
+ $error_msg = _('Failed to delete subproject.');
+ session_redirect('/plugins/'.$pluginExtSubProj->name.'/?type=admin&group_id='.$group_id.'&pluginname='.$pluginExtSubProj->name.'&error_msg='.urlencode($error_msg));
+}
+
+$feedback = _('Sub project succesfully deleted.');
+session_redirect('/plugins/'.$pluginExtSubProj->name.'/?type=admin&group_id='.$group_id.'&pluginname='.$pluginExtSubProj->name.'&feedback='.urlencode($feedback));
+?>
function getProjectAdminAddExtSubProjAction($group_id) {
return '?group_id='.$group_id.'&type=admin&pluginname='.$this->name.'&action=addExtSubProj';
}
+ function getProjectAdminDelExtSubProjAction($group_id, $url) {
+ return '?group_id='.$group_id.'&type=admin&pluginname='.$this->name.'&action=delExtSubProj&url='.urlencode($url);
+ }
/**
* getHeader - initialize header and js
* @param string type : user, project (aka group)
return true;
}
+ function getSubProjects($project_id) {
+ $res = db_query_params('SELECT sub_project_url from plugin_extsubproj_subprojects where project_id=$1', array($project_id));
+ if (!$res) {
+ return false;
+ }
+ $returnArr = array();
+ while ($row = db_fetch_array($res)) {
+ $returnArr[] = $row['sub_project_url'];
+ }
+ return $returnArr;
+ }
+
+ function addExtSubProj($project_id, $url) {
+ // TODO verify URL
+ // check if not already in the existing subprojects (even for another project)
+ // TODO first check with HTTP then check with HTTPS
+ $res = db_query_params('SELECT count(*) from plugin_extsubproj_subprojects where sub_project_url=$1', array($url));
+ if ($res && db_result($res, 0, 'count') == '0') {
+ $res = db_query_params('INSERT INTO plugin_extsubproj_subprojects (project_id, sub_project_url) VALUES ($1, $2)',
+ array($project_id, $url));
+ if (!$res) {
+ return false;
+ }
+ return true;
+ }
+ }
+
+ function delExtSubProj($project_id, $url) {
+ // TODO verify URL
+ // check if not already in the existing subprojects (even for another project)
+ // TODO first check with HTTP then check with HTTPS
+ $res = db_query_params('SELECT count(*) from plugin_extsubproj_subprojects where sub_project_url=$1', array($url));
+ if ($res && db_result($res, 0, 'count') > '0') {
+ $res = db_query_params('DELETE FROM plugin_extsubproj_subprojects WHERE project_id=$1 AND sub_project_url=$2',
+ array($project_id, $url));
+ if (!$res) {
+ return false;
+ }
+ return true;
+ }
+ }
+
/**
* getConf - return the configuration defined at project level
*
* @param integer the group id
* @return array the configuration array
*/
- function getConf($project_id) {
+ /*function getConf($project_id) {
$resConf = db_query_params('SELECT * from plugin_extsubproj_subprojects where project_id=$1',array($project_id));
if (!$resConf) {
return false;
return $returnArr;
}
-
+ */
// function CallHook ($hookname, &$params) {
// global $use_extsubprojplugin,$G_SESSION,$HTML;
global $use_tooltips;
global $group_id;
-/*$pluginExtSubProjProjectConf = $pluginExtSubProj->getConf($group_id);
-if (!$pluginExtSubProjProjectConf) {
- echo '<div class="error">'._('Cannot retrieve data from DB').'</div>';
-} else {
-*/
- echo $HTML->boxTop(_("Manage project's external subprojects"));
-
- echo '<form method="post" action="'.$pluginExtSubProj->getProjectAdminAddExtSubProjAction($group_id).'">';
- echo '<table>';
-
- echo '<tr><td><label id="extSubProj-newsubprojecturl" ';
- if ($use_tooltips)
- echo 'class="tabtitle-nw" title="'._('URL of the new subproject.').'"';
- echo ' >'._('URL').'</label></td><td><input type="text" name="newsubprojecturl"';
- echo '/></td></tr>';
-
- echo '</table>';
- echo '<input type="submit" value="'._('Add').'" />';
- echo '</form>';
-
- echo $HTML->boxBottom();
-//}
+$subProjects = $pluginExtSubProj->getSubProjects($group_id);
+
+if(is_array($subProjects)) {
+ $tablearr = array(_('Subproject URL'),'');
+ echo $HTML->listTableTop($tablearr);
+
+ foreach ($subProjects as $url) {
+ echo '
+ <tr>
+ <td>'.$url.'
+ </td>
+ <td>
+ <a href="'. $pluginExtSubProj->getProjectAdminDelExtSubProjAction($group_id, $url) .'">'._('delete').'</a>
+ </td>
+ </tr>';
+ }
+
+ echo $HTML->listTableBottom();
+}
+
+echo $HTML->boxTop(_("Manage project's external subprojects"));
+
+echo '<form method="post" action="'.$pluginExtSubProj->getProjectAdminAddExtSubProjAction($group_id).'">';
+echo '<table>';
+
+echo '<tr><td><label id="extSubProj-newsubprojecturl" ';
+if ($use_tooltips)
+ echo 'class="tabtitle-nw" title="'._('URL of the new subproject.').'"';
+echo ' >'._('URL').'</label></td><td><input type="text" name="newsubprojecturl"';
+echo '/></td></tr>';
+
+echo '</table>';
+echo '<input type="submit" value="'._('Add').'" />';
+echo '</form>';
+
+echo $HTML->boxBottom();
+
?>
exit_error(sprintf(_('First activate the %s plugin through the Project\'s Admin Interface'), $pluginExtSubProj->name), 'home');
}
$action = getStringFromRequest('action');
- switch ($action) {
- case 'addExtSubProj': {
- global $gfplugins;
- include($gfplugins.$pluginExtSubProj->name.'/actions/'.$action.'.php');
- break;
- }
- default: {
- // do nothing, see getProjectAdminView() below
- break;
+ if($action) {
+ switch ($action) {
+ case 'delExtSubProj':
+ case 'addExtSubProj': {
+ global $gfplugins;
+ include($gfplugins.$pluginExtSubProj->name.'/actions/'.$action.'.php');
+ break;
+ }
+ default: {
+ $pluginExtSubProj->redirect($_SERVER['HTTP_REFERER'], 'error_msg', _('Unknown action.'));
+ break;
+ }
}
}
// params needed by site_project_header() inside getHeader()