Index: /trunk/alternc/patches/class/m_mail_egw.php
===================================================================
--- /trunk/alternc/patches/class/m_mail_egw.php	(revision 781)
+++ /trunk/alternc/patches/class/m_mail_egw.php	(revision 782)
@@ -4,8 +4,7 @@
 class m_mail_egw extends m_mail {
 
-	function _createpop($mail,$dom,$pass) {
-	
-		if ($this->_add_egw_account($mail,$dom,$pass) )
-			if (parent::_createpop($mail,$dom,$pass))
+	function create($dom_id, $mail, $type = "", $dontcheck = false) {
+       	   if ($this->_add_egw_account($dom_id, $mail, $type = "", $dontcheck = false))
+			if (parent::create($dom_id,$mail,$type="",$dontcheck=false))
 				return true;
 			else
@@ -15,8 +14,8 @@
 	}
 
-	function _deletepop($mail,$dom) {
+	function delete($mail_id) {
 	
-		if ($this->_del_egw_account($mail,$dom) )
-			if (parent::_deletepop($mail,$dom))
+		if ($this->_del_egw_account($mail_id) )
+			if (parent::delete($mail_id))
 				return true;
 			else
@@ -26,50 +25,39 @@
 	}
 
-	function _updatepop($mail,$dom,$pass) {
+	function _add_egw_account($dom_id, $mail, $type = "", $dontcheck = false) {
+        global $err, $db, $quota, $dom, $hooks, $L_EGW_ADMINCLI, $L_EGW_ADMINUSER, $L_EGW_ADMINCLAVE;
+	$res = true;
+	        $err->log("mail", "create_egwclass", "$mail $dom_id");
+	$domain = $dom->get_domain_byid($dom_id);
+		$err->log("mail", "create_egwclass", "$mail $domain");
+
+
+	// armamos el commando a executar en el cli de egw
+	$admincli= $L_EGW_ADMINCLI;
+	$command= "--edit-user";              // Command to be performed
+	$adminuser= $L_EGW_ADMINUSER;
+	$adminclave= $L_EGW_ADMINCLAVE;
+	//$adminclave= "*******";
+
+	$firstname = $mail;			// the left side of the email
+	$lastname= "-";                         // we have a generic lastname
+	$pass= "*****"; //TEMPORARY
+	$email = $account = $mail ."@" .$domain; // account and email are the same
+	$expires= "never";
+	$canchangepw= "yes";
+	$anonuser= "no";
+//	$primarygroup = $domain[$size-3];   // domains in .ar starts at the third level
+	$primarygroup= "cta"; //TEMPORARY
+//	$secondarygroup = $domain[$size-4]; // sub-domain is used as a secondary group
+	$homedir = "/home/". $mail ."_" .$domain; // everyone can have a home    
+	$loginshell = "/bin/bash";		  // everyone can have a shell
+
+ 	$go= $admincli ." " .$command ." " .$adminuser ."," .$adminclave .",\"" .$account ."\"," .$firstname ."," .$lastname ."," .$pass .",\"" .$email ."\"," .$expires ."," .$canchangepw ."," .$anonuser ."," .$primarygroup ;
 	
-		if ($this->_update_passwd_egw_account($mail,$dom,$pass) )
-			if (parent::_updatepop($mail,$dom,$pass))
-				return true;
-			else
-				return false;
-		else
-			return false;
-	}
+	$go= $go ."," .$homedir ."," .$loginshell ;
 
-	function _add_egw_account($mail,$dom,$pass) {
+	echo "<h3>Creamos la cuenta en la base ldap</h3>";
+//	echo "<h4>$go</h4>"; // LA CLAVE SALE... ACA
 
-		$res = true;
-		$domain = explode('.',$dom);
-		$size = count($domain);
-		if (  $size >= 3 && 
-			$domain[$size-2] == "org" &&
-			$domain[$size-1] == "ar" ) {
-
-			$admincli= $GLOBALS["L_EGW_ADMINCLI"];
-			$command= "--edit-user";                        // Command to be performed
-			$adminuser = $GLOBALS["L_EGW_ADMINUSER"];
-			$adminclave = $GLOBALS["L_EGW_ADMINCLAVE"];
-                        $firstname = $mail;				// the left side of the email
-			$lastname= "-";                                 // we have a generic lastname
-			$email = $account = $mail ."@" .$dom;		// account and email are the same
-			$expires= "never";
-			$canchangepw= "yes";
-			$anonuser= "no";
-			$primarygroup = $domain[$size-3];		// domains in .ar starts at the third level
-			$secondarygroup = $domain[$size-4];		// the sub-domain is used as a secondary group
-			$homedir = "/home/". $mail ."_" .$dom;		// everyone can have a home    
-			$loginshell = "/bin/bash";			// everyone can have a shell
-
-			$go= $admincli ." " .$command ." " .$adminuser ."," .$adminclave .",\"" .$account ."\"," .$firstname ."," .$lastname ."," .$pass .",\"" .$email ."\"," .$expires ."," .$canchangepw ."," .$anonuser ."," .$primarygroup ;
-			
-			if (isset($secondarygroup)) {
-			$go= $go ."," .$secondarygroup ;
-			}
-
-			$go= $go ."," .$homedir ."," .$loginshell ;
-
-		 	echo "<h3>Creamos la cuenta en la base ldap</h3>";
-			//echo $go;
-			// exit();
 			$cod = exec($go);
 			if ($cod)
@@ -81,73 +69,42 @@
 			 //$res = false;
 			}	
-		}
-		return $res;
+
+	// mandamos el codigo de error en /var/log/alternc/bureau.log 
+	$err->log("mail_egw", "create", $cod);
+
+
+	// para no morir aca...
+	return $res;
 	}	
 
-	function _del_egw_account($mail,$dom) {
+	function _del_egw_account($mail_id) {
+	global $err, $db, $hooks;
+                $err->log("mail", "delete_egwclass", $mail_id);
+	$res = true;
 
-		$res = true;
-		$domain = explode('.',$dom);
-		$size = count($domain);
-		if (  $size >= 3 && 
-			$domain[$size-2] == "org" &&
-			$domain[$size-1] == "ar" ) {
+	// desde el mail_id buscamos el dominio
+	$query="SELECT domaine FROM domaines 
+		WHERE id=(SELECT domain_id FROM address where id=\"$mail_id\")";
+	$result_dominio=mysql_query($query);
 
-			$admincli= $GLOBALS["L_EGW_ADMINCLI"];
-			$command= "--delete-user";                        // Command to be performed
-			$adminuser = $GLOBALS["L_EGW_ADMINUSER"];
-			$adminclave = $GLOBALS["L_EGW_ADMINCLAVE"];
-			$email = $account = $mail ."@" .$dom;
+// print resultados...
+while($row = mysql_fetch_assoc($result_dominio)){
+foreach($row as $cname => $cvalue){print "$cname: $cvalue\t";}
+print "\r\n";
+}
+	// desde el mail_id buscamos la primera parte del mail
+ 	$query="SELECT address FROM address WHERE id=\"$mail_id\"";
+//	print "$query";
+	$result_mail=mysql_query($query);	
+// print resultados...
+while($row = mysql_fetch_assoc($result_mail)){
+foreach($row as $cname => $cvalue){print "$cname: $cvalue\t";}
+print "\r\n";
+}
 
-			$go= $admincli ." " .$command ." " .$adminuser ."," .$adminclave .",\"" .$account ."\"" ;
-			
-		 	echo "<h3>Borramos la cuanta en la base ldap</h3>";
-			//echo $go;
-			// exit();
-			$cod = exec($go);
-			if ($cod)
-                        {
-                         // die ($cod);
-                         echo "<p class=\"error\">";
-                         echo $cod;
-                         echo "</p>";
-                         //$res = false;
-			}	
-		}
-		return $res;
+	// para no morir aca...
+	return $res;
 	}	
 
-	function _update_passwd_egw_account($mail,$dom,$pass) {
-
-		$res = true;
-		$domain = explode('.',$dom);
-		$size = count($domain);
-		if (  $size >= 3 && 
-			$domain[$size-2] == "org" &&
-			$domain[$size-1] == "ar" ) {
-
-			$admincli= $GLOBALS["L_EGW_ADMINCLI"];
-			$command= "--change-pw";                        // Command to be performed
-			$adminuser = $GLOBALS["L_EGW_ADMINUSER"];
-			$adminclave = $GLOBALS["L_EGW_ADMINCLAVE"];
-			$email = $account = $mail ."@" .$dom;
-
-			$go= $admincli ." " .$command ." " .$adminuser ."," .$adminclave .",\"" .$account ."\"," .$pass ;
-			
-		 	echo "<h3>Actualizamos la contrasena en la base ldap</h3>";
-			//echo $go;
-			// exit();
-			$cod = exec($go);
-			if ($cod)
-			{
-                         // die ($cod);
-			 echo "<p class=\"error\">";
-                         echo $cod;
-			 echo "</p>";
-                         //$res = false;
-			}	
-		}
-		return $res;
-	}	
 }
 
