Index: /trunk/alternc/patches/class/m_mail_egw.php_alternc095
===================================================================
--- /trunk/alternc/patches/class/m_mail_egw.php_alternc095	(revision 781)
+++ /trunk/alternc/patches/class/m_mail_egw.php_alternc095	(revision 781)
@@ -0,0 +1,154 @@
+<?
+require_once("m_mail.php");
+
+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))
+				return true;
+			else
+				return false;
+		else
+			return false;
+	}
+
+	function _deletepop($mail,$dom) {
+	
+		if ($this->_del_egw_account($mail,$dom) )
+			if (parent::_deletepop($mail,$dom))
+				return true;
+			else
+				return false;
+		else
+			return false;
+	}
+
+	function _updatepop($mail,$dom,$pass) {
+	
+		if ($this->_update_passwd_egw_account($mail,$dom,$pass) )
+			if (parent::_updatepop($mail,$dom,$pass))
+				return true;
+			else
+				return false;
+		else
+			return false;
+	}
+
+	function _add_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= "--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)
+			{
+			 // die ($cod);
+                         echo "<p class=\"error\">";
+                         echo $cod;
+                         echo "</p>";
+			 //$res = false;
+			}	
+		}
+		return $res;
+	}	
+
+	function _del_egw_account($mail,$dom) {
+
+		$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= "--delete-user";                        // Command to be performed
+			$adminuser = $GLOBALS["L_EGW_ADMINUSER"];
+			$adminclave = $GLOBALS["L_EGW_ADMINCLAVE"];
+			$email = $account = $mail ."@" .$dom;
+
+			$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;
+	}	
+
+	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;
+	}	
+}
+
+?>
