Bei einer Kundensite haben wir die Anforderung, dass berechtigte Frontenduser über ein Webformular eigene Angebote erstellen können, die dann als einzelne Contenido-Artikel angelegt sein sollen (wie eine NewsList) und für eine andere Applikation in xml-code umgewandelt werden sollen.
So weit so gut.
Ein Webformular mit den nötigen Daten war anhand der Vorlage des Kontaktformluars schnell erstellt. Auch die Artikelgenerierung mit conEditFirstTime() klappt so weit. Jetzt möchte der Kunde aber, dass in dem Moment, wenn ein Artikel automatisch erstellt wird, auch ein Workflow initiiert wird, der dann die weitere Verarbeitung des Artikel steuert. (der für die Kategorie in der die Angebote liegen zuständige Redakteur wird informiert, dass ein neuer Artikel vorliegt; dieser schaltet ihn frei oder schickt ihn zurück).
Erstellen von Workflow ist auch soweit klar, aber wie baue ich das in das Webformular ein. Der Workflow muss im Prinzip initiiert werden, sobald im Formular auf "speichern" geklickt wird. Das Ganze passiert im Frontend. Hier müssen aber Funktionen im Backend ausgelöst werden. Ich möchte das Rad nicht neu erfinden, denn im Backend gibt es ja schon das Workflow-Plugin.
Ich kenn mich bei Contenido von der Design- und Administrationsseite schon ziemlich gut aus. Bin aber kein Programmierer. Vielleicht finde ich so schneller einen Lösungsansatz als würde ich jetzt tagelang reverse engineering betreiben.
Wir verwenden
contenido 4.8.14 mit AMR
PHP 5.2.6 (muss PHP 5.2.x sein, weil eine andere App am Server noch nicht kompatibel zu 5.3.x ist)
Apache 2.2
Das Modul, um das sich alles dreht, sieht folgendermaßen aus:
Eingabe:
Code: Alles auswählen
?><?php
/**
* $RCSfile$
*
* Description: Offer Construction Kit Input
*
* @version 0.0.1
* @author Peter Korinek
* @copyright IP.NETCOM <www.ipnetcom.at>
*
* {@internal
* created 2011-14-12
* }}
*
* $Id$
*/
cInclude("frontend", "includes/functions.input.helper.php");
cInclude("includes", "functions.con.php");
cInclude("includes", "functions.api.string.php");
global $db;
# Base settings
$aSettings["Category"] = "CMS_VALUE[10]";
# Checking base settings
$aSettings["Category"] = (!is_numeric($aSettings["Category"]) || $aSettings["Category"] <= 0) ? 0 : $aSettings["Category"];
?>
<table border="0">
<tr>
<td><?php echo mi18n("category");?></td>
<td><?php echo fncBuildCategorySelect("CMS_VAR[10]", $aSettings["Category"], 0, "")?></td>
</tr>
<tr>
<td><?php echo mi18n("template");?></td>
<td>
<SELECT name="CMS_VAR[11]">
<?php
$query = "SELECT * FROM " . $cfg['tab']['tpl'] . " WHERE idclient = " . $client . " ORDER BY idtpl ASC";
//echo $query;
$db->query($query);
while ($db->next_record())
{
$value = "CMS_VALUE[11]";
if ($db->f('idtpl') == $value) {$selected = "selected";}
else {$selected = "";}
echo '<OPTION value="'.$db->f('idtpl').'" ' . $selected .'>'.$db->f('name').'</OPTION>';
}
?>
</SELECT>
</td>
</tr>
<tr>
<td><?php echo mi18n("imagefolder");?></td>
<td><input type="text" name="<?php echo "CMS_VAR[9]";?>" value="<?php echo "CMS_VALUE[9]";?>"></td>
</tr>
<tr>
<td colspan="2">
<br />
<?php echo mi18n("CAPTCHA-Einstellungen");?>
</td>
</tr>
<tr>
<td><?php echo mi18n("captcha-Pfad");?></td>
<td>
<input type="text" name="<?php echo "CMS_VAR[0]";?>" value="<?php echo "CMS_VALUE[0]";?>"><br />
<?php echo mi18n("captcha-cms-path");?>
</td>
</tr>
<tr>
<td><?php echo mi18n("captcha-width");?></td>
<td><input type="text" name="<?php echo "CMS_VAR[1]";?>" value="<?php echo "CMS_VALUE[1]";?>"></td>
</tr>
<tr>
<td><?php echo mi18n("captcha-height");?></td>
<td><input type="text" name="<?php echo "CMS_VAR[2]";?>" value="<?php echo "CMS_VALUE[2]";?>"></td>
</tr>
<tr>
<?php
$c1 = '';
$c2 = '';
switch (CMS_VALUE[3]) {
case "png" :
$c1 = ' checked';
break;
case "jpeg" :
$c2 = ' checked';
break;
default :
$c1 = ' checked';
}
?>
<td><?php echo mi18n("captcha-type");?></td>
<td><input type="radio" name="<?php echo "CMS_VAR[3]";?>" value="png"<?php echo $c1;?>> png
<input type="radio" name="<?php echo "CMS_VAR[3]";?>" value="jpg"<?php echo $c2;?>> jpeg<br/>
</td>
</tr>
<tr>
<?php
$c1 = '';
$c2 = '';
switch (CMS_VALUE[4]) {
case "rand" :
$c1 = ' checked';
break;
case "list" :
$c2 = ' checked';
break;
default :
$c1 = ' checked';
}
?>
<td><?php echo mi18n("captcha-string-type");?></td>
<td><input type="radio" name="<?php echo "CMS_VAR[4]";?>" value="rand"<?php echo $c1;?>> <?php echo mi18n("random");?>
<input type="radio" name="<?php echo "CMS_VAR[4]";?>" value="list"<?php echo $c2;?>> <?php echo mi18n("wordlist");?><br/>
</td>
</tr>
<tr>
<td><?php echo mi18n("captcha-string-length");?></td>
<td><input type="text" name="<?php echo "CMS_VAR[5]";?>" value="<?php echo "CMS_VALUE[5]";?>"></td>
</tr>
<tr>
<td><?php echo mi18n("font-size");?></td>
<td>
<input type="text" name="<?php echo "CMS_VAR[6]";?>" value="<?php echo "CMS_VALUE[6]";?>"><br />
<?php echo mi18n("allowed values");?>
</td>
</tr>
<tr>
<td><?php echo mi18n("background-intensity");?></td>
<td>
<input type="text" name="<?php echo "CMS_VAR[7]";?>" value="<?php echo "CMS_VALUE[7]";?>"><br />
<?php echo mi18n("background-intensity-default-values");?>
</td>
</tr>
<tr>
<td><?php echo mi18n("background-colour");?></td>
<td>
<input type="text" name="<?php echo "CMS_VAR[8]";?>" value="<?php echo "CMS_VALUE[8]";?>"><br />
<?php echo mi18n("background-colour-desc");?>
</td>
</tr>
</table>
<?php
Code: Alles auswählen
<?php
/**
* $RCSfile$
*
* Description: Offer Construction Kit Output
*
* @version 0.0.1
* @author Peter Korinek
* @copyright IP.NETCOM <www.ipnetcom.at>
*
* {@internal
* created 2011-14-12
* last modified 2011-14-12
* }}
*
* $Id$
**/
#Includes
// cInclude("classes", "class.phpmailer.php");
// Captcha
$captcha_path = "CMS_VALUE[0]";
$captcha_image_width = "CMS_VALUE[1]";
$captcha_image_height = "CMS_VALUE[2]";
$captcha_image_type = "CMS_VALUE[3]";
$captcha_string_source = "CMS_VALUE[4]";
$captcha_string_length = "CMS_VALUE[5]";
$captcha_string_size = "CMS_VALUE[6]";
$captcha_background_intensity = "CMS_VALUE[7]";
$captcha_background_color = "CMS_VALUE[8]";
$imagefolder = "CMS_VALUE[9]";
$category = "CMS_VALUE[10]";
$template = "CMS_VALUE[11]";
// CMS_VARs initialisieren Ende
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
// Captcha-Einstellungen setzen
// Session starten
@session_start();
// Captcha-Class einbinden
include_once($captcha_path."config.php");
include_once($captcha_path."crypt.class.php");
// Crypt-Class initialisieren
$GLOBALS['crypt_class'] = new crypt_class();
$captchaimg = '<img id="user_captcha_img" alt="Sicherheitsabfrage" src="'.$cfgClient[$client]['path']['htmlpath'].$captcha_path.'image.php?source='.$captcha_string_source.'&length='.$captcha_string_length.'&size='.$captcha_string_size.'&intensity='.$captcha_background_intensity.'&color='.$captcha_background_color.'&width='.$captcha_image_width.'&height='.$captcha_image_height.'&type='.$captcha_image_type.'&'.md5(uniqid(rand(), true)).'"'.$einzeltag.'>';
// $captchaimg = '<img id="user_captcha_img" alt="Sicherheitsabfrage" src="'.$cfgClient[$client]['path']['htmlpath'].'/'.$captcha_path.'image.php?source='.$captcha_string_source.'&length='.$captcha_string_length.'&size='.$captcha_string_size.'&intensity='.$captcha_background_intensity.'&color='.$captcha_background_color.'&width='.$captcha_image_width.'&height='.$captcha_image_height.'&type='.$captcha_image_type.'&'.md5(uniqid(rand(), true)).'"'.$einzeltag.'>';
$captchavalid = '<input id="user_captcha_string" type="text" name="user_captcha_string" onFocus="javascript:inputFocusStyle(this)" onBlur="javascript:inputBlurStyle(this)">';
$captchapath = '<input id="captcha_path" type="hidden" name="captcha_path" value="'.$captcha_path.'">';
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
include($cfg['path']['css'] .'style.offerForm.php');
$userid=$auth->auth['uid'];
$username=$auth->auth['uname'];
if (!isset($tpl) || !is_object($tpl)) {
$tpl = new Template();
}
cInclude('classes', 'class.article.php');
cInclude('classes', 'class.template.php');
cInclude('includes', 'functions.tpl.php');
cInclude('includes', 'functions.con.php');
cInclude('includes', 'functions.api.string.php');
#Create form
$sFormAction = $sess->url("front_content.php?idcat=$idcat&idart=$idart&parentid=$parentid");
$tpl->set("s", 'form_action', $sFormAction);
$tpl->set("s", "SELLER", mi18n("seller"));
$tpl->set("s", "EMAIL", mi18n("email"));
$tpl->set("s", "TITLE", mi18n("title"));
$tpl->set("s", "TOTAL", mi18n("total"));
$tpl->set("s", "UNIT", mi18n("unit"));
$tpl->set("s", "UNITOPTION1", mi18n("unitoption1"));
$tpl->set("s", "UNITOPTION2", mi18n("unitoption2"));
$tpl->set("s", "UNITOPTION3", mi18n("unitoption3"));
$tpl->set("s", "UNITOPTION4", mi18n("unitoption4"));
$tpl->set("s", "UNITOPTION5", mi18n("unitoption5"));
$tpl->set("s", "UNITOPTION6", mi18n("unitoption6"));
$tpl->set("s", "AMOUNT", mi18n("amount"));
$tpl->set("s", "PRICE", mi18n("price"));
$tpl->set("s", "VALID", mi18n("valid"));
$tpl->set("s", "VALIDFROM", mi18n("validfrom"));
$tpl->set("s", "DESCRIPTION", mi18n("description"));
$tpl->set("s", "IMAGE", mi18n("image"));
$tpl->set("s", "SEARCH", mi18n("search"));
$tpl->set("s", "SAVE", mi18n("save"));
$tpl->set("s", "RESET", mi18n("reset"));
$tpl->set("s", "AMOUNTTEXT", mi18n("amounttext"));
$tpl->set("s", "IMAGEFOLDER", $imagefolder);
$tpl->set("s", "CATEGORY", $category);
$tpl->set("s", "TEMPLATE", $template);
$tpl->set("s", "USERNAME", $username);
$tpl->set("s", "USERID", $userid);
$tpl->set("s", "PFLICHTFELDER", mi18n("Bitte alle Felder ausfüllen"));
$tpl->set('s', 'HTMLROOT', $cfgClient[$client]["path"]["htmlpath"]);
//captcha
$tpl->set('s', 'CAPTCHAIMG', $captchaimg);
$tpl->set('s', 'CAPTCHAVALID', $captchavalid);
$tpl->set('s', 'CAPTCHACODE', mi18n("captchacode"));
$tpl->set('s', 'CAPTCHATEXT', mi18n("captchatext"));
$tpl->set('s', 'CAPTCHAPATH', $captchapath);
//$_POST array
$tpl->set('s', 'SELLERVALUE', $_POST['seller']);
$tpl->set('s', 'EMAILVALUE', $_POST['email']);
$tpl->set('s', 'TITLEVALUE', $_POST['title']);
$tpl->set('s', 'AMOUNTVALUE', $_POST['amount']);
$tpl->set('s', 'TOTALAMOUNTVALUE', $_POST['totalAmount']);
$tpl->set('s', 'PRICEVALUE', $_POST['price']);
$tpl->set('s', 'VALIDFROMVALUE', $_POST['validfrom']);
$tpl->set('s', 'VALIDVALUE', $_POST['valid']);
$tpl->set('s', 'DESCRIPTIONVALUE', $_POST['description']);
$tpl->set('s', 'UNITOPTION6VALUE', $_POST['unitoption6value']);
$c1 = '';
$c2 = '';
$c3 = '';
$c4 = '';
$c5 = '';
$c6 = '';
switch ($_POST['unitoption'])
{
case mi18n("unitoption1") :
$c1 = ' checked';
break;
case mi18n("unitoption2") :
$c2 = ' checked';
break;
case mi18n("unitoption3") :
$c3 = ' checked';
break;
case mi18n("unitoption4") :
$c4 = ' checked';
break;
case mi18n("unitoption5") :
$c5 = ' checked';
break;
case mi18n("unitoption6") :
$c6 = ' checked';
}
$tpl->set('s', 'CHECKED1', $c1);
$tpl->set('s', 'CHECKED2', $c2);
$tpl->set('s', 'CHECKED3', $c3);
$tpl->set('s', 'CHECKED4', $c4);
$tpl->set('s', 'CHECKED5', $c5);
$tpl->set('s', 'CHECKED6', $c6);
if (!isset ($_POST['send']))
{
#generate form
$tpl->generate($cfgClient[$client]["path"]["frontend"]."templates/angebotformular.html");
}
elseif ($_POST['send'] == 1)
{
/*?>
<script>alert('<?=$_POST['user']?>')</script>
<?php
*/
#offer has been configured, continue with checking user input, error handling and automatically generate new article in a given category
#Check user input
$noerrors = true;
$msg = '';
@session_start();
//init vars
$filename = $_FILES['image']['name'];
$filetemp = $_FILES['image']['tmp_name'];
// default captcha-path
if (!isset($_POST["captcha_path"])) {$_POST["captcha_path"] = "includes/captcha/";}
// Captcha-Class einbinden
$captcha_path = $cfgClient[$client]['path']['frontend'].$_POST["captcha_path"];
include_once($captcha_path."config.php");
include_once($captcha_path."crypt.class.php");
// Crypt-Class initialisieren
$GLOBALS['crypt_class'] = new crypt_class();
/* CAPTCHA ENDE */
// CAPTCHA - prüfen
if (!$_POST['user_captcha_string'] || empty($_POST['user_captcha_string']))
{
$noerrors = false;
$msg = mi18n("Captcha-Eingabe fehlt!").'<br/>';
}
elseif ($_POST['user_captcha_string'] != $GLOBALS['crypt_class']->base64_decode_advanced($_SESSION['captcha_string']))
{
$noerrors = false;
$msg = mi18n("captchaError").'<br/>';
}
// CAPTCHA - prüfen ENDE
if ($_POST['email'] == '') {
$noerrors = false;
$msg .= mi18n("Bitte geben Sie Ihre E-Mail-Adresse ein!")."<br/>";
}
if ($_POST['title'] == '') {
$noerrors = false;
$msg .= mi18n("Bitte geben Sie eine Überschrift ein!")."<br/>";
}
if ($_POST['totalAmount'] == '') {
$noerrors = false;
$msg .= mi18n("Bitte geben Sie eine Gesamtmenge ein!")."<br/>";
}
if ($_POST['unitoption'] == '') {
$noerrors = false;
$msg .= mi18n("Bitte wählen eine Einheit aus!")."<br/>";
}
if ($_POST['unitoption'] == 6 && $_POST['unitoption6value'] == '') {
$noerrors = false;
$msg .= mi18n("Bitte geben Sie eine Bezeichnung für die Einheit an!")."<br/>";
}
if ($_POST['amount'] == '') {
$noerrors = false;
$msg .= mi18n("Bitte geben Sie Stückmengen ein!")."<br/>";
}
if ($_POST['price'] == '') {
$noerrors = false;
$msg .= mi18n("Bitte geben Sie einen Preis ein!")."<br/>";
}
if ($_POST['description'] == '') {
$noerrors = false;
$msg .= mi18n("Bitte geben Sie einen Beschreibung ein!")."<br/>";
}
if (file_exists($cfgClient[$client]["path"]["htmlpath"].$cfgClient[$client]['upload'].$imagefolder.'/'.$_POST['user'].'/'.$filename))
{
$noerrors = false;
$msg .= mi18n("Die Datei existiert bereits.")."<br/>";
}
//errors so far? STOP!
if ($noerrors == false)
{
echo "<p>";
#Errors have been found
echo '<IMG src="'.$cfgClient[$client]["path"]["htmlpath"].'images/icons/exclamation.png" width="16" height="16" align="absmiddle"> <strong>'.mi18n("Beim Versenden sind folgende Fehler aufgetreten:").'</strong><br/>';
echo $msg.'<br/>';
echo '<a href="javascript:history.back();">‹ '.mi18n("zurück").'</a>';
#generate form
$tpl->generate($cfgClient[$client]["path"]["frontend"]."templates/angebotformular.html");
}
//No errors so far? CONTINUE!
else {
global $db;
// create new article and write content in it
// step#1: create Article
$article_id = conEditFirstTime($_POST['category'],array($_POST['category']),$idart,0,$_POST['template'],$idartlang,$lang,$_POST['title'],$summary,$artspec,date('Y-m-d H:i:s'),date('Y-m-d H:i:s'),$_POST['user'],1,$_POST['validfrom'],$_POST['valid'],$artsort,$keyart=0);
// step#2 template
$sql_string = "SELECT * FROM " . $cfg['tab']['tpl_conf'] ." ORDER BY idtplcfg DESC";
$db->query($sql_string);
$db->next_record();
$idtplcfg = $db->f("idtplcfg");
$idtplcfg++;
$upd_string = "INSERT INTO " . $cfg['tab']['tpl_conf'] . " (idtplcfg, idtpl,created,lastmodified,author) VALUES (".$idtplcfg.", ".$_POST['template'].", '".date('Y-m-d H:i:s')."', '".date('Y-m-d H:i:s')."','".$_POST['user']."')";
$db->query($upd_string);
//step 2.5 tplcfg -> article
$idartlang = getArtLang($article_id, $lang);
$sql_string = "UPDATE " . $cfg['tab']['art_lang'] . " SET idtplcfg='".$idtplcfg."' WHERE idartlang='".$idartlang."'";
$db->query($sql_string);
//Daten step by step
//imageupload
if (!is_dir($cfgClient[$client]['upload'].$imagefolder))
{
mkdir($cfgClient[$client]['upload'].$imagefolder);
chmod($cfgClient[$client]['upload'].$imagefolder,757);
}
if (!is_dir($cfgClient[$client]['upload'].$imagefolder.'/'.$_POST['user']))
{
mkdir($cfgClient[$client]['upload'].$imagefolder.'/'.$_POST['user']);
chmod($cfgClient[$client]['upload'].$imagefolder.'/'.$_POST['user'],757);
}
move_uploaded_file($filetemp, $cfgClient[$client]['upload'].$imagefolder.'/'.$_POST['user'].'/'.$filename);
$imagesize = getimagesize($cfgClient[$client]['upload'].$imagefolder.'/'.$_POST['user'].'/'.$filename);
if ($_POST['unitoption'] == mi18n('unitoption6'))
{
$units = $_POST['unitoption6value'];
}
else {$units = $_POST['unitoption'];}
$amountlist = explode("|", $_POST["amount"]);
$amountstring = "";
// $length = strlen($amountlist);
foreach($amountlist as $id => $value)
{
$amountstring .= '<li>'.$value.' '.$units.'</li>';
}
$contentstring = '
<table border="0" cellspacing="5" cellpadding="5" align="left" style="width: 100%;">
<tr>
<td colspan="3" id="title"><h2 style="color:'.$cfg['col']['1'].';font-size:14px;">'.$_POST["title"].'</h2></td>
</tr>
<tr>
<td style="width: 200px; text-align: right;">'.mi18n("total").':</td>
<td id="totalAmount">'.$_POST["totalAmount"].' '.$units.'</td>
<td id="image" rowspan="8"><img src="'.$cfgClient[$client]["path"]["htmlpath"].$cfgClient[$client]['upload'].$imagefolder.'/'.$_POST['user'].'/'.$filename.'" border="0" width="'.$imagesize[0].'" height="'.$imagesize[1].'" /></td>
</tr>
<tr>
<td style="width: 200px; text-align: right;">'.mi18n("amount").':</td>
<td>
<ul id="amountlist">'
.$amountstring.
'</ul>
</td>
</tr>
<tr>
<td style="width: 200px; text-align: right;">'.mi18n("price").':</td>
<td id="price">'.$_POST['price'].' €</td>
</tr>
<tr>
<td id="description" colspan="2" align="center" valign="middle" style="padding: 20px;"><strong>'.$_POST['description'].'</strong></td>
</tr>
<tr>
<td style="text-align: right;">'.mi18n('validfrom').':</td>
<td id="validfrom" style="width: 200px;">'.$_POST['validfrom'].'</td>
</tr>
<tr>
<td style="text-align: right;">'.mi18n('valid').':</td>
<td id="valid" style="width: 200px;">'.$_POST['valid'].'</td>
</tr>
<tr>
<td style="text-align: right; padding-bottom: -5px;">'.mi18n('seller').':</td>
<td id="seller" style="width: 200px;">'.$_POST['seller'].'</td>
</tr>
<tr>
<td style="text-align: right;">'.mi18n('email').':</td>
<td id="email" style="width: 200px;">'.$_POST['email'].'</td>
</tr>
</table>';
conSaveContentEntry($idartlang, 'CMS_HEAD', 1, $_POST['title'], $bForce = false);
conSaveContentEntry($idartlang, 'CMS_HTML', 1, $contentstring, $bForce = false);
//response
echo '<div class="intro"><br /><IMG src="'.$cfgClient[$client]["path"]["htmlpath"].'images/logoelement_pfeil_neu.png" valign="top" align="absmiddle" alt="Info" title="Info" width="16" height="16"> ' . mi18n("Angebot erstellt").': '.$_POST['title'].'. <br />';
/*
echo 'DEBUG:<br/>';
echo 'Template '. $_POST['template'].'<br/>';
echo 'idtplcfg '. $idtplcfg.'<br/>';
echo 'idartlang '. $idartlang.'<br/>';
echo 'lang ' . $lang.'<br/>';
*/
}
}
?>
Ach ja, bei conEditFirstTime hapert auch noch:
Wenn ich mir nun dieser automatisch angelegten Artikel genauer anschaue, stelle ich fest, dass nicht alle Artikeleigenschaften übernommen werden:
- der Autor (in diesem Fall der Name des FE-Users - das ist auch wahrscheinlich hier das Problem - scheint nicht auf, obwohl er in die DB [con__art_lang glaube ich jetzt, ohne es zu verifizieren] geschrieben wird
Start- und Endzeit werden nicht in die DB geschrieben, in den DB-Feldern steht "0000-00-00 00:00:00" sind also quasi leer.
peko