hi
i found a solution
description:
1. i call my poll module in this way
{cms_module module='polls' lang="fr_FR" poll_id="opinion_de"}
where poll_id is a parameter added by me
2. in table cms_module_polls add a new column i named it poll_id
alter table cms_module_polls add column poll_id varchar(30) default ''
this id i will use it to identify the poll which i want to put on the page
3. i change the polllist.php file also
this is the new one
Code: Select all
<?php
?>
<table cellspacing="0" class="pagetable">
<thead>
<tr>
<th class="pagepos">Poll ID</th>
<th class="pagepos"><?php echo $this->Lang("pollname");?></th>
<th class="pagepos"><?php echo $this->Lang("pollstatus");?></th>
<th class='pageicon'><?php echo $this->Lang("activepoll");?></th>
<th class='pageicon'><?php echo $this->Lang("edit");?></th>
<th class='pageicon'><?php echo $this->Lang("delete");?></th>
<th class="pagepos"><?php echo $this->Lang("pollstartdate");?></th>
<th class="pagepos"><?php echo $this->Lang("pollclosedate");?></th>
<th class="pagepos"><?php echo $this->Lang("pollinfo");?></th>
</tr>
</thead>
<tbody>
<?php
//tr row1/2
$db=$this->GetDb();
$q="SELECT * FROM ".cms_db_prefix()."module_polls";
$result=$db->Execute($q);
if ($result && $result->RecordCount()>0) {
$rowclass="row1";
while ($row=$result->FetchRow()) {
echo "<tr class='$rowclass'>";
echo "<td class='pagepos'>".$row["poll_id"]."</td>";
echo "<td class='pagepos'>".$row["name"]."</td>";
$status="";
if ($row["closed"]==0) {
if ($row["id"]==$activepoll) {
$status=$this->Lang("open");
} else {
$text="<img src='themes/default/images/icons/system/false.gif' class='systemicon' alt='Close poll'>";
$status=$this->Lang("open")." ".$this->CreateLink($id, "closepoll",$returnid, $text, array("pollid"=>$row["id"]), $this->lang("confirmclosepoll"));
}
} else {
$status=$this->Lang("closed");
}
echo "<td class='pagepos'>".$status."</td>";
echo "<td class='pagepos'>";
if ($row["closed"]==0) {
if ($row["id"]==$activepoll) {
echo "<img src='themes/default/images/icons/system/true.gif' alt='Active poll' class='systemicon'>";
} else {
$text="<img src='themes/default/images/icons/system/false.gif' alt='Close poll' class='systemicon'>";
echo $this->CreateLink($id, "activatepoll",$returnid, $text, array("pollid"=>$row["id"]));
}
} else {
echo " ";
}
echo "</td>";
echo "<td class='pagepos'>";
$text="<img src='themes/default/images/icons/system/edit.gif' alt='Close poll' class='systemicon'>";
echo $this->CreateLink($id, "editpoll",$returnid, $text, array("pollid"=>$row["id"]));
echo "</td>";
echo "<td class='pagepos'>";
if ($row["id"]==$activepoll) {
echo " ";
} else {
$text="<img src='themes/default/images/icons/system/delete.gif' alt='Delete poll' class='systemicon'>";
echo $this->CreateLink($id, "deletepoll",$returnid, $text, array("pollid"=>$row["id"]),$this->Lang("confirmdeletepoll"));
}
echo "</td>";
echo "<td class='pagepos'>".date("d/m/Y",$row["createtime"])."</td>";
echo "<td class='pagepos'>".($row["closed"]==1?date("d/m/Y",$row["closetime"]):" ")."</td>";
echo "<td class='pagepos'>";
if ($row["closed"]) {
echo $this->Lang("pollranfor")." ";
echo ceil((($row["closetime"]-$row["createtime"]) / (3600*24)));
echo " ".$this->Lang("days");
} else {
echo $this->Lang("pollhasbeenrunningfor")." ";
echo ceil(((time()-$row["createtime"]) / (3600*24)));
echo " ".$this->Lang("days");
}
echo "</td></tr>";
if ($rowclass=="row1") $rowclass="row2"; else $rowclass="row1";
}
} else {
}
?>
</tbody>
</table>
<?php
echo $this->CreateFormStart($id,"addpoll",$returnid);
echo $this->CreateInputSubmit($id,"addpoll",$this->Lang("addpoll"));
echo $this->CreateFormEnd();
?>
this is not neccessary to change for the functionality-just in case if you want to see the poll_id s
4. i change the file action.addpoll.php to this
Code: Select all
if (!isset($gCms) || !$this->VisibleToAdminUser()) exit;
$value="";
if (isset($params["submit"]) || isset($params["submitadd"])) {
if (strlen($params["pollname"])>1 && strlen($params["poll_id"])>1) {
$db=$this->GetDb();
$newid=$db->GenID(cms_db_prefix()."module_polls_seq");
$q="INSERT INTO ".cms_db_prefix()."module_polls (id,name,closed,createtime,poll_id) VALUES (?,?,?,?,?)";
$p=array($newid,$params["pollname"],0,time(),$params["poll_id"]);
$result=$db->Execute($q,$p);
if (isset($params["submit"])) {
$this->Redirect($id,"defaultadmin",$returnid,array("module_messages"=>$this->Lang("polladded")));
} else {
$this->Redirect($id,"editpoll",$returnid,array("module_messages"=>$this->Lang("polladded"),"pollid"=>$newid));
}
} else {
echo $this->ShowErrors($this->Lang("pollnamerequired"));
//Fallthrough to form
}
} elseif (isset($params["cancel"])) {
$this->Redirect($id,"defaultadmin",$returnid);
}
echo "<h3>".$this->Lang("addnewpoll")."</h3>";
echo $this->CreateFormStart($id,"addpoll",$returnid);
echo $this->CreateInputTextWithLabel($id,"pollname",$value,40,128,"",$this->Lang("pollname"));
echo $this->CreateInputTextWithLabel($id,"poll_id",$value,40,128,"","Poll ID");
echo "<br/>";
echo "<br/>";
echo $this->CreateInputSubmit($id,"submit",$this->Lang("add"));
echo $this->CreateInputSubmit($id,"submitadd",$this->Lang("addandaddoptions"));
echo $this->CreateInputSubmit($id,"cancel",$this->Lang("cancel"));
echo $this->CreateFormEnd();
in this way i insert a poll id in the table also which is a string
5. i change the action.default.php file
i add this code at the top of the page
Code: Select all
$pollid=$this->PollToShow();
if(isset($params['poll_id']))
{
$db=$this->GetDb();
$q="SELECT id FROM ".cms_db_prefix()."module_polls WHERE poll_id = ? ORDER BY createtime DESC";
$p=array($params["poll_id"]);
$result=$db->Execute($q,$p);
if ($result && $result->RecordCount()>0)
{
$row=$result->FetchRow();
$pollid = $row['id'];
}
}
in this way if the poll_id parameter is set we take the last inserted id from the db for that poll_id
if it is not set or it not exist than the id remains the active one
thats all folks
i hope it is useful for someone
special thanks for Dee for the suggestions - thanks