Accéder au contenu.
Menu Sympa

devel - [Devel] r276 - branches/dui

Objet : devel-adl

Archives de la liste

[Devel] r276 - branches/dui


Chronologique Discussions 
  • From: svn AT agendadulibre.org
  • To: devel AT agendadulibre.org
  • Subject: [Devel] r276 - branches/dui
  • Date: Mon, 28 May 2007 22:58:54 +0200 (CEST)
  • List-archive: <http://lolut.utbm.info/pipermail/devel>
  • List-id: Developpement de l'Agenda du Libre <devel.agendadulibre.org>

Author: ldayot
Date: Mon May 28 22:58:53 2007
New Revision: 276

Log:
Mise a jour des formulaires de soumission et de moderation avec les
categories de tags.



Modified:
branches/dui/funcs.inc.php
branches/dui/moderate.php
branches/dui/submit.php

Modified: branches/dui/funcs.inc.php
==============================================================================
--- branches/dui/funcs.inc.php (original)
+++ branches/dui/funcs.inc.php Mon May 28 22:58:53 2007
@@ -620,20 +620,65 @@

if ($tags != "")
{
+ $result .= format_tags($tags);
+ /*
$tags = split(" ", $tags);
$result .= "<p>Tags: ";
for ($i = 0; $i < count($tags); $i++)
- {
- $result .= "<a href=\"listevents.php?tag=" . $tags[$i] . "\">" .
$tags[$i] . "</a>";
- if ($i != count($tags) - 1)
- $result .= ", ";
- }
+ {
+ $result .= "<a href=\"listevents.php?tag=" . $tags[$i] . "\">" .
$tags[$i] . "</a>";
+ if ($i != count($tags) - 1)
+ $result .= ", ";
+ }
$result .= "</p>";
+ */
}

return $result;
}

+// Display tags grouped by categories
+// $tags is a string of tag
+function format_tags($tags)
+{
+ global $db;
+
+ $res = $db->query("SELECT tags.name AS tag, tags.category_id as cat_id,
tags_categories.name as category ".
+ "FROM tags LEFT JOIN tags_categories ON category_id=tags_categories.id ".
+ "WHERE tags.name IN ('". str_replace(" ", "','", $tags). "') ".
+ "ORDER BY tags_categories.name");
+
+ $result = "";
+ $cat = "-1";
+ while ($rec = $db->fetchObject($res))
+ {
+ if ($cat != $rec->category)
+ {
+ if ($cat != "-1")
+ if ($cat_id==0)
+ $last_line = "<p>". _("Tags"). " : ". implode(", ", $result_tags).
"</p>";
+ else
+ $result .= "<p>". $cat. " : ". implode(", ", $result_tags).
"</p>";
+ $cat = $rec->category;
+ unset($result_tags);
+ $result_tags = array();
+ }
+ $result_tags[] = $rec->tag;
+ $cat_id=$rec->cat_id;
+ }
+ if ($cat != "-1")
+ if ($cat_id==0)
+ $last_line = "<p>". _("Tags"). " : ". implode(", ", $result_tags).
"</p>";
+ else
+ $result .= "<p>". $cat. " : ". implode(", ", $result_tags). "</p>";
+
+ if (isset($last_line))
+ $result .= $last_line;
+
+ return $result;
+} // end function
+
+
/**
* Format an event in an ASCII format, suitable for e-mails
*
@@ -754,6 +799,30 @@
$submitter = escape_form_string($submitter);
$tags = escape_form_string($tags);

+ if (file_exists("tiny_mce"))
+ {
+ ?>
+<!-- tinyMCE -->
+<script language="javascript" type="text/javascript"
src="tiny_mce/tiny_mce.js"></script>
+<script language="javascript" type="text/javascript">
+ // Notice: The simple theme does not use all options some of them
are limited to the advanced theme
+ tinyMCE.init({
+ mode : "textareas",
+ language : "fr",
+ theme : "advanced",
+ theme_advanced_buttons1 : "bold,italic,underline,separator,
bullist,numlist,undo,redo,link,unlink",
+ theme_advanced_buttons2 : "",
+ theme_advanced_buttons3 : "",
+ theme_advanced_toolbar_location : "top",
+ theme_advanced_toolbar_align : "left",
+ theme_advanced_path_location : "bottom",
+ extended_valid_elements : "a[name|href|target|title|onclick]"
+ });
+</script>
+<!-- /tinyMCE -->
+<?php
+ } // end if tiny_mce
+
?>
<table>

@@ -866,11 +935,29 @@
<input type="text" size="70" name="__event_submitter" value="<?php echo
$submitter;?>"/><br/>
</td>
</tr>
+<?php

+ $aCategoryTags = selectWithCategoryTags(explode(" ", $tags));
+ foreach ($aCategoryTags->HTML as $category_id=>$aSelect)
+ {
+ echo "<tr><td>{$aSelect['categoryName']}:</td>".
+ "<td>{$aSelect['categoryDescription']}<br />".
+ "{$aSelect['HTMLSelect']} </td>\n</tr>\n";
+ }
+ $aTags = explode(' ', $aCategoryTags->tagsRest);
+?>
<tr>
- <td>
+ <td rowspan="2">
Tags:
</td>
+ <td><?php
+
+ $oTags = selectWithoutCategoryTags($aTags, $fieldName="tags[0][]",
$multiple=true);
+ echo _("Dans les tags connus"). " : <br />". $oTags->HTML;
+ $tags = $oTags->tagsRest;
+
+ ?></td></tr>
+ <tr>
<td>
<i>Tags pour l'�v�nement. Les tags sont s�par�s par des
espaces. Un tag ne peut contenir que des lettres minuscules,
@@ -945,49 +1032,121 @@
return $return;
}

-// Function to choose tags
-// $aTags is an array (category_id=>tag_name)
+// Function to choose tags (only one per category)
+// $aTags is an array (tag_name)
// output if HTML string select part of form
function selectTagsHTML($aTags)
{
+ $oTags = selectWithoutCategoryTags($aTags, $fieldName="tags[tag]",
$multiple=false);
+ $return = "<strong>". _("Tags"). "</strong> : {$oTags->HTML}<br />\n";
+ $aCategoryTags = selectWithCategoryTags($aTags);
+ foreach ($aCategoryTags as $category_id=>$aSelect)
+ {
+ $return .= "<strong>{$aSelect['categoryName']}</strong> :
{$aSelect['HTMLSelect']} {$aSelect['categoryDescription']}<br />\n";
+ }
+ return $return;
+} // end
+
+// Function to choose tags in categories (only one per category)
+// $aTags is an array (tag_name)
+// output is array (categoryName=>, categoryDescription=>, HTMLSelect=>)
+function selectWithCategoryTags($aTags)
+{
global $db;
// TODO Select only tags used twice or more.
// Or sort and class tags in alphabetical optgroup
- $ret = $db->query ("SELECT tags.name AS tag, tags_categories.id AS
category_id, tags_categories.name AS category, tags_categories.description as
description FROM tags LEFT JOIN tags_categories ON
tags_categories.id=category_id GROUP BY category_id, tags.id ORDER BY
tags_categories.name, tags.name");
+ $ret = $db->query ("SELECT tags.name AS tag, tags_categories.id AS
category_id, tags_categories.name AS category, tags_categories.description as
description FROM tags LEFT JOIN tags_categories ON
tags_categories.id=category_id WHERE category_id>0 GROUP BY category_id,
tags.id ORDER BY tags_categories.name, tags.name");
if ($ret == FALSE)
{
error ("Erreur lors de la recherche des tags");
put_footer();
exit;
}
+
$category_id=-1;
- $return = "";
+ $return = array();
+ $tagsSelect = array();
+
while ($row = $db->fetchObject($ret))
{
if ($category_id!=$row->category_id)
{
if ($category_id!=-1)
- $return .= " ".($description!="" ? $description : "").
"</select>\n<br />\n";
- if ($category_id==-1)
- {
- $category_id = 0;
- $category="tag";
- }
- else
{
- $category_id = $row->category_id;
- $category = $row->category;
+ $return[$category_id]["HTMLSelect"] .= "</select>";
+ $return[$category_id]["categoryDescription"] = ($description!="" ?
$description : "");
}
- $return .= "<strong>{$category}". _(" :"). "</strong> ";
+ $category_id = $row->category_id;
$description = $row->description;
- $return .= "<select name='tags[{$category}]'>\n";
- $return .= " <option value='' ". (!isset($aTags[$category]) ?
"selected='selected' " : ""). "></option>";
+ $category = $row->category;
+ $return[$category_id]["categoryName"] = $category;
+
+ $return[$category_id]["HTMLSelect"] = "<select
name='tags[{$category}]'>\n".
+ " <option value='' ".
+ (!isset($aTags[$category]) ? "selected='selected' " : "").
"></option>\n";
} // end if
- $return .= " <option value='{$row->tag}' ". (isset($aTags[$category]) &&
$aTags[$category]==$row->tag ? "selected='selected' " : "").
">{$row->tag}</option>";
+ $return[$category_id]["HTMLSelect"] .= " <option value='{$row->tag}' ".
+ ($inArray = in_array($row->tag, $aTags) ? "selected='selected' " : "").
+ ">{$row->tag}</option>\n";
+ if ($inArray) $tagsSelect[] = $row->tag;
} // end while
+ if ($category_id!=-1)
+ {
+ $return[$category_id]["HTMLSelect"] .= "</select>";
+ $return[$category_id]["categoryDescription"] = ($description!="" ?
$description : "");
+ }
$db->freeResult($ret);
- $return .= " </select>\n<br />\n";
- return $return;
+
+ $oTags->HTML = $return;
+ $oTags->tagsSelect = implode(' ', $tagsSelect);
+ $oTags->tagsRest = implode(' ', array_diff($aTags, $tagsSelect));
+ return $oTags;
+}
+
+// Function to choose tags
+// $aTags is an array (tag_name)
+// output if HTML string select part of form
+function selectWithoutCategoryTags($aTags=array(), $fieldName="tags[0]",
$multiple=false)
+{
+ global $db;
+ // TODO Select only tags used twice or more.
+ // Or sort and class tags in alphabetical optgroup
+ $ret = $db->query ("SELECT name, COUNT(event_id) AS n FROM tags LEF JOIN
tags_events ON tag_id=id WHERE category_id=0 GROUP BY id ORDER BY name");
+ if ($ret == FALSE)
+ {
+ error ("Erreur lors de la recherche des tags");
+ put_footer();
+ exit;
+ }
+
+ $tagsSelect = array();
+ $n=0;
+
+ $skeleton = "<label for='%1\$s'>%1\$s</label>". ($multiple ?
+ "<input type=\"checkbox\" name=\"$fieldName\" %2\$s value=\"%1\$s\"
id=\"%1\$s\" /><label> / " :
+ "<option value=\"%1\$s\" %2\$s />%1\$s</option>");
+
+ $return = ($multiple ? "" : "<select
name='{$fieldName}'>\n<option></option>\n");
+
+ while ($row = $db->fetchObject($ret))
+ {
+ // only tags used twice or more
+ $inArray = in_array($row->name, $aTags);
+ if ($row->n>1)
+ {
+ $return .= sprintf($skeleton, $row->name, ($inArray ? ($multiple ?
"checked='checked'" : "selected='selected'") : ""));
+ if ($inArray) $tagsSelect[] = $row->name;
+ $n++;
+ }
+ } // end while
+
+ if (!$multiple) $return .= "</select>\n";
+ $db->freeResult($ret);
+
+ $oTags->HTML = $return;
+ $oTags->tagsSelect = implode(' ', $tagsSelect);
+ $oTags->tagsRest = implode(' ', array_diff($aTags, $tagsSelect));
+ return $oTags;
}

// Get tags name for one event

Modified: branches/dui/moderate.php
==============================================================================
--- branches/dui/moderate.php (original)
+++ branches/dui/moderate.php Mon May 28 22:58:53 2007
@@ -42,6 +42,7 @@
}

$oldevent = $db->fetchObject ($ret);
+ $oldevent->tags = eventTagsList($oldevent->id);

$sql = "UPDATE events SET " .
"title=" . $db->quote_smart ($title) . ", "
.
@@ -65,7 +66,6 @@
return -1;
}

-
// about tags
$event_id = $id;
// delete old
@@ -105,7 +105,7 @@
$description, $city, $region, $locality,
$url, $contact, $submitter, $tags);

- $diff = arr_diff (split ("\n", $oldevent_str), split ("\n",
$newevent_str), 1);
+ $diff = @arr_diff (split ("\n", $oldevent_str), split ("\n",
$newevent_str), 1);

calendar_mail ($moderatorlist, "",
"�dition de l'�v�nement '" . $title . "'",
@@ -159,7 +159,7 @@
format_ascii_event ($db, $row->title,
date_mysql2timestamp($row->start_time),
date_mysql2timestamp($row->end_time),
$row->description, $row->city,
$row->region, $row->locality,
- $row->url, $row->contact,
$row->submitter, $row->tags) . "\n" .
+ $row->url, $row->contact,
$row->submitter, eventTagsList($row->id)) . "\n" .
"=====================================================\n\n" .
"Merci de votre contribution � l'Agenda du Libre et �
bient�t !\n\n".
"-- \nL'�quipe de mod�ration");
@@ -255,6 +255,15 @@
*/
else if (isset($_POST['__event_save']))
{
+ $event_tags = $_POST['__event_tags'];
+
+ foreach($_POST['tags'] as $aTags)
+ if (is_array($aTags))
+ $event_tags .= " ". implode(' ', $aTags);
+ else
+ $event_tags .= " ". $aTags;
+ $event_tags = str_replace(" ", " ", $event_tags);
+
$ret = save_event ($db, $id,
$_POST['__event_title'],
mktime($_POST['__event_start_hour'],
@@ -276,7 +285,7 @@
$_POST['__event_url'],
$_POST['__event_contact'],
$_POST['__event_submitter'],
- $_POST['__event_tags'],
+ $event_tags,
$session->value ("agenda_libre_id"));

if ($ret == 0)

Modified: branches/dui/submit.php
==============================================================================
--- branches/dui/submit.php (original)
+++ branches/dui/submit.php Mon May 28 22:58:53 2007
@@ -233,6 +233,18 @@
$_POST['__event_end_year']);
}

+if (isset($_POST['__event_tags']))
+{
+ // format tags
+ $event_tags = $_POST['__event_tags'];
+ foreach($_POST['tags'] as $aTags)
+ if (is_array($aTags))
+ $event_tags .= " ". implode(' ', $aTags);
+ else
+ $event_tags .= " ". $aTags;
+ $event_tags = trim(str_replace(" ", " ", $event_tags));
+}
+
/* If user submitted event */
if (isset($_POST['__event_save']))
{
@@ -245,7 +257,7 @@
$_POST['__event_url'],
$_POST['__event_contact'],
$_POST['__event_submitter'],
- $_POST['__event_tags']);
+ $event_tags);

if ($ret == 0)
{
@@ -271,7 +283,7 @@
$_POST['__event_url'],
$_POST['__event_contact'],
$_POST['__event_submitter'],
- $_POST['__event_tags']);
+ $event_tags);
echo "<hr/>";
}
}
@@ -279,6 +291,7 @@
/* Preview event */
else if (isset($_POST['__event_preview']))
{
+
echo "<hr/>";
echo format_event ($db, $_POST['__event_title'],
$start, $end,
@@ -289,7 +302,7 @@
$_POST['__event_url'],
$_POST['__event_contact'],
$_POST['__event_submitter'],
- $_POST['__event_tags']);
+ $event_tags);
echo "<hr/>";
}

@@ -378,7 +391,7 @@
@$_POST['__event_url'],
@$_POST['__event_contact'],
@$_POST['__event_submitter'],
- @$_POST['__event_tags'],
+ @$event_tags,
TRUE);

echo "</form>\n";





Archives gérées par MHonArc 2.6.16.

Haut de le page