Пример #1
0
        public override void DataBind()
        {
            if (this._bound)
            {
                return;
            }
            _bound = true;

            if (this.NamingContainer == null)
            {
                return;
            }

            memberRow = DataBinder.Eval(this.NamingContainer, "DataItem") as DataRow;
            if (memberRow == null)
            {
                DataRowView drv = DataBinder.Eval(this.NamingContainer, "DataItem") as DataRowView;
                if (drv == null)
                {
                    ErrorContext.Add("invalid-dataitem", "Invalid DataItem for profile picture, DataItem must be DataRow or DataRowView (other wise needs programming to work)");
                    this.Visible = false;
                    return;
                }
                memberRow = drv.Row;
            }

            base.DataBind();
        }
Пример #2
0
        public bool AddPage(string Name, string Title, string Description, bool Virtual, string content, Languages language)
        {
            if (StringUtils.IsNullOrWhiteSpace(Name))
            {
                return(false);
            }

            if (this.GetPages("Name='" + StringUtils.SQLEncode(Name) + "'").Count > 0)
            {
                ErrorContext.Add("validation", "Another page with the same name already exists");
                return(false);
            }

            PagesDS.PagesRow row = DS.Pages.NewPagesRow();

            row.Name         = Name;
            row.Title        = Title;
            row.Description  = Description;
            row.Virtual      = Virtual;
            row.LastModified = DateTime.Now;
            row.Keywords     = "";

            DS.Pages.Rows.Add(row);

            AcceptChanges();

            CreatePageFile(Name, content, language);

            return(true);
        }
Пример #3
0
        public int UpdateOperator(
            int MemberId,
            string Email, string AlternateEmail,
            string FirstName, string LastName,
            int GroupId,
            string UserName, string Password,
            string SecretQuestion, string SecretAnswer, int status,
            string style, int ChangedBy, bool JoinNewsletter,
            string PrivateComments, string Comments)
        {
            MembersManager mMgr = new MembersManager();
            int            ret  = mMgr.UpdateMember(MemberId,
                                                    UserName, Password,
                                                    Email, AlternateEmail,
                                                    SecretQuestion, SecretAnswer, "", FirstName, "", LastName, null, null,
                                                    status, lw.WebTools.WebContext.Profile.UserId,
                                                    JoinNewsletter, PrivateComments, Comments
                                                    );

            CreateOperatorProfile(MemberId, GroupId, style);

            if (ret == -1)
            {
                ErrorContext.Add("UsernameEmailExists", ContentManager.ErrorMsg(Errors.UsernameEmailExists));
            }
            return(ret);
        }
Пример #4
0
        public void DeletePictures(int id, SiteSections section)
        {
            var q = GetPictures(id, section);

            foreach (Picture p in q)
            {
                p.Status = (short)Status.Deleted;
            }
            try
            {
                string path = WebContext.Server.MapPath(GetPicturesDirectory(id, section));
                if (Directory.Exists(path))
                {
                    Directory.Delete(path);
                }
            }
            catch (Exception Ex)
            {
                ErrorContext.Add("fail to delete pictures for id: " + id.ToString(), Ex.Message);
            }
            finally
            {
                Save();
            }
        }
Пример #5
0
        public string GetPagePath(int PageId)
        {
            PagesDS.PagesRow page = GetPage(PageId);

            if (page != null)
            {
                if (page["Url"] != System.DBNull.Value)
                {
                    return(WebContext.Root + "/" + page["Url"].ToString());
                }
                if (page["GroupId"] != System.DBNull.Value)
                {
                    PagesDS.GroupsRow group     = GetGroup(page.GroupId);
                    string            groupPath = GetGroupPath(group);

                    string pagePath = page.Name.Replace(StringUtils.ToURL(groupPath) + "-", "");

                    return(groupPath + "/" + pagePath);
                }

                return(null);
            }

            ErrorContext.Add("page-not-found", new Exception("The Id supplied does not exist"));
            return(null);
        }
Пример #6
0
        public static void CheckAccess(string _params, UserStatus stat, string redirect)
        {
            if (String.IsNullOrEmpty(redirect))
            {
                Config cfg = new Config();
                redirect = cfg.GetKey(parameters.LoginURL);
            }

            if (!WebContext.Profile.UserLogged)
            {
                string url = WebContext.Request.ServerVariables["URL"];
                if (WebContext.Request.QueryString.Count > 0)
                {
                    url += string.Format("?{0}", WebContext.Request.QueryString);
                }

                if (_params != "")
                {
                    _params = string.Format("&{0}", _params);
                }

                WebContext.Response.Redirect(string.Format("{0}/{3}?return={1}{2}",
                                                           WebContext.Root, WebContext.Server.UrlEncode(url), _params, redirect));
            }
            if (((int)WebContext.Profile.CurrentUserStatus & (int)stat) == 0)
            {
                ErrorContext.Add("permission", ContentManager.ErrorMsg(lw.CTE.Errors.InvalidPermission));
            }
        }
Пример #7
0
        public bool CheckQuantities()
        {
            bool passed = true;

            StringBuilder cond = new StringBuilder();

            string sep = "";

            foreach (DataRow row in ShoppingItems.BasketItems.Rows)
            {
                if (row["OptionsKey"] == System.DBNull.Value || row["OptionsKey"].ToString() == "")
                {
                    cond.Append(string.Format("{0}(Inventory<{1} and ItemId={2})",
                                              sep, row["Quantity"], row["ItemId"]));
                }
                else
                {
                    cond.Append(string.Format("{0}(Inventory<{1} and ItemId={2} and OptionsKey='{3}')",
                                              sep, row["Quantity"], row["ItemId"], row["OptionsKey"]));
                }
                sep = " or ";
            }
            ItemsFullViewAdp adp = new ItemsFullViewAdp();

            DataTable dt = adp.GetForInventoryConfirmation(cond.ToString());


            if (dt.Rows.Count > 0)
            {
                StringBuilder missedInventoryItems = new StringBuilder();

                foreach (DataRow row in dt.Rows)
                {
                    if (row["OptionsKey"] == DBNull.Value)
                    {
                        DataRow[] rows = ShoppingItems.BasketItems.Select(string.Format("ItemId={0}", row["ItemId"]));
                        missedInventoryItems.Append(string.Format("{0} - {1}: Original Quantity({2})<BR />",
                                                                  rows[0]["Title"], rows[0]["ItemNumber"], rows[0]["Quantity"]));
                        rows[0]["Quantity"] = Int32.Parse(row["Inventory"].ToString());
                    }
                    else
                    {
                        DataRow[] rows = ShoppingItems.BasketItems.Select(string.Format("ItemId={0} and OptionsKey='{1}'", row["ItemId"], row["OptionsKey"]));
                        missedInventoryItems.Append(string.Format("{0} - {1} ({3}): Original Quantity({2})<BR />",
                                                                  rows[0]["Title"], rows[0]["ItemNumber"], rows[0]["Quantity"], rows[0]["Description"]));
                        rows[0]["Quantity"] = Int32.Parse(row["Inventory"].ToString());
                    }
                }
                ErrorContext.Add("wrong-inventory", missedInventoryItems.ToString());
                AdjustTotals(true);
                passed = false;
            }

            return(passed);
        }
Пример #8
0
 public void AcceptChanges()
 {
     try
     {
         DS.AcceptChanges();
         XmlManager.SetDataSet(config, DS);
     }
     catch (Exception Ex)
     {
         ErrorContext.Add("Pages-Save", "Could not save pages.config.<BR>" + Ex.Message);
     }
 }
Пример #9
0
        void bind()
        {
            if (_bound)
            {
                return;
            }

            DataObj = DataBinder.Eval(this.NamingContainer, "DataItem");
            _bound  = DataObj != null;

            if (!_bound)
            {
                return;
            }

            string name = _namingFormat;

            if (!String.IsNullOrWhiteSpace(_namingFrom))
            {
                name = String.Format(name,
                                     ControlUtils.GetBoundedDataField(this.NamingContainer, _namingFrom)
                                     );
                this.Value = ControlUtils.GetBoundedDataField(this.NamingContainer, _namingFrom).ToString();
                this.ID    = name;
                this.Attributes["name"] = name;
            }

            if (!String.IsNullOrWhiteSpace(_boundTo))
            {
                try
                {
                    object obj = ControlUtils.GetBoundedDataField(this.NamingContainer, _boundTo);
                    if (obj.GetType() == true.GetType())
                    {
                        this.Checked = (bool)obj;
                    }
                    else
                    {
                        this.Checked = float.Parse(obj.ToString()) > 0;
                    }
                }
                catch (Exception ex)
                {
                    ErrorContext.Add("BoundedCheckbox: " + _boundTo + " " + _namingFrom, "Can only be bounded to a boolean field");
                }
            }
        }
Пример #10
0
        /// <summary>
        /// Send Email As Attachement File
        /// </summary>
        /// <param name="str">Value added to the file name; Default: DateTime in seconds</param>
        public void SendAsAttachement(string str, string FormLink)
        {
            MailManager mMgr = new MailManager();

            string folder = WebContext.Server.MapPath("~/temp");

            if (!Directory.Exists(folder))
            {
                Directory.CreateDirectory(folder);
            }

            string       tempFile = WebContext.Server.MapPath("~/temp/" + StringUtils.ToURL(this.Email + "-" + str) + ".htm");
            StreamWriter sr       = new StreamWriter(tempFile);

            sr.Write(MailManager.LoadData(this.BodyFile, this.Data));
            sr.Close();
            sr.Dispose();
            sr = null;

            _attachements.Add(tempFile);

            MailAddress _from = new MailAddress(this.From, this.FromName == null ? this.From : this.FromName);

            if (string.IsNullOrEmpty(FormLink))
            {
                mMgr.SendMail(_from, this.ToList, this.CCList, this.BCCList, this.Subject, true, "Please download the attachment.", "", _attachements);
            }
            else
            {
                string _link = string.Format("Please download the attachment.<br /><p><a href=\"{0}\">Click here</a> to manage this form</p>", FormLink);
                mMgr.SendMail(_from, this.ToList, this.CCList, this.BCCList, this.Subject, true, _link, "", _attachements);
            }
            for (int i = 0; i < _attachements.Count; i++)
            {
                try
                {
                    File.Delete(_attachements[i].ToString());
                }
                catch (Exception Ex)
                {
                    ErrorContext.Add("attachment-delete", "Could not delete attachment: " + _attachements[i].ToString() + "<BR>" + Ex.Message);
                }
            }
            this._attachements.Clear();
        }
Пример #11
0
        public MembersDs.MembersRow AddMember(string userName,
                                              string email, string AlternateEmail,
                                              string password,
                                              string SecretQuestion, string SecretAnswer,
                                              string title,
                                              string firstName, string middleName, string lastName,
                                              Gender?gender, DateTime?dateOfBirth, int?status, int Privacy,
                                              string Comments, string PrivateComments, int?ChangedBy, bool?JoinNewsletter, string FullName, string NativeFullName)
        {
            string cond = "";

            if (email == "*****@*****.**")
            {
                cond = string.Format("Username='******'",
                                     StringUtils.SQLEncode(userName));
            }
            else
            {
                cond = string.Format("UserName='******' or Email='{1}'",
                                     StringUtils.SQLEncode(userName),
                                     StringUtils.SQLEncode(email));
            }

            if (GetMembers(cond).Rows.Count > 0)
            {
                if (email != null && email.Trim() != "")
                {
                    ErrorContext.Add("validation", ContentManager.ErrorMsg(Errors.UserAlreadyExists));
                    return(null);
                }
            }

            MembersDsTableAdapters.MembersTableAdapter adp = new lw.Members.MembersDsTableAdapters.MembersTableAdapter();
            MembersDs.MembersDataTable dt = adp.AddMember(
                System.Guid.NewGuid(),
                userName, EncryptPassword(password), status,
                title,
                firstName, middleName, lastName, (short?)gender, email, AlternateEmail,
                dateOfBirth,
                DateTime.Now, DateTime.Now, DateTime.Now, false, SecretQuestion,
                SecretAnswer, ChangedBy, JoinNewsletter, Privacy, FullName, NativeFullName);
            return((MembersDs.MembersRow)dt.Rows[0]);
        }
Пример #12
0
        public bool UpdatePageProperties(int PageId, string Name, string Title, string Description, string Keywords)
        {
            if (this.GetPages(string.Format("Name='{0}' And PageId<>{1}", Name, PageId)).Count > 0)
            {
                ErrorContext.Add("validation", "Another page with the same name already exists");
                return(false);
            }

            PagesDS.PagesRow row = GetPage(PageId);

            row.Name         = Name;
            row.Title        = Title;
            row.Description  = Description;
            row.LastModified = DateTime.Now;
            row.Keywords     = Keywords;

            row.Table.AcceptChanges();
            AcceptChanges();

            return(true);
        }
Пример #13
0
        /// <summary>
        /// Default Image sizes is 0.
        /// </summary>>
        public void UpdateImage(int networkId, Stream BytesStream, string fileName, bool autoResize,
                                bool deleteOld, int largeWidth, int largeHeight, int thumbWidth, int thumbHeight,
                                int mediumWidth, int mediumHeight)
        {
            try
            {
                if (BytesStream.Length != 0)
                {
                    string path = WebContext.Server.MapPath("~/temp");
                    path = Path.Combine(path, fileName);

                    lw.Utils.IO.SaveStream(BytesStream, path);

                    UpdateImage(networkId, path, false, true, largeWidth, largeHeight,
                                thumbWidth, thumbHeight, mediumWidth, mediumHeight);
                }
            }
            catch (Exception ex)
            {
                ErrorContext.Add("add-image", "Unable to add image.<br><span class=hid>" + ex.Message + "</span>");
            }
        }
Пример #14
0
        public bool DeleteNewsType(int TypeId)
        {
            DataView types = GetChildrenNewsTypes(TypeId);

            foreach (DataRowView drv in types)
            {
                DeleteNewsType((Int32)drv["TypeId"]);
            }

            try
            {
                var type = GetType(TypeId);

                if (!StringUtils.IsNullOrWhiteSpace(type.Image))
                {
                    string path = WebContext.Server.MapPath(Path.Combine(WebContext.StartDir, Folders.NewsTypesFolder));

                    if (Directory.Exists(path))
                    {
                        var Image = type.Image;
                        if (File.Exists(Path.Combine(path, Image)))
                        {
                            File.Delete(Path.Combine(path, Image));
                        }
                    }
                }

                NewsTypesData.NewsTypes.DeleteOnSubmit(type);
                NewsTypesData.SubmitChanges();
            }
            catch (Exception ex)
            {
                ErrorContext.Add("delete-newstype", "Unable to delete news type.<br />" + ex.Message);
                return(false);
            }

            return(true);
        }
Пример #15
0
        /// <summary>
        /// Uploads and Adds the uploaded files to the comments' folder
        /// TODO: Add these file name to an xml field inside the DB so they can be used without file access
        /// </summary>
        /// <param name="TableName">Comments Table Name</param>
        /// <param name="CommentId">Comment ID</param>
        /// <returns>List of Added Files</returns>
        public ArrayList AddFiles(string TableName, int CommentId)
        {
            ArrayList ret  = new ArrayList();
            string    path = CommentFolder(TableName, CommentId);

            for (int i = 0; i < WebContext.Request.Files.Count; i++)
            {
                HttpPostedFile file = WebContext.Request.Files[i];
                if (file.ContentLength > 0)
                {
                    string temp = Path.Combine(path, Path.GetFileName(file.FileName));
                    try
                    {
                        file.SaveAs(WebContext.Server.MapPath(temp));
                        ret.Add(temp);
                    }
                    catch (Exception ex)
                    {
                        ErrorContext.Add("comment-files", ex);
                    }
                }
            }
            return(ret);
        }
Пример #16
0
        /// <summary>
        /// Delete a single picture
        /// </summary>
        /// <param name="id">id of the relation</param>
        /// <param name="fileName">File Name of the pictre</param>
        /// <param name="section">related Section</param>
        /// <returns>true of deleted</returns>
        public bool DeletePicture(int id, string fileName, SiteSections section)
        {
            Picture picture = GetPicture(id, fileName, section);

            if (picture != null)
            {
                picture.Status = (short)Status.Deleted;

                try
                {
                    string path = WebContext.Server.MapPath(GetPicturePath(picture));
                    if (File.Exists(path))
                    {
                        File.Delete(path);
                    }

                    path = WebContext.Server.MapPath(GetThumbPicturePath(picture));
                    if (File.Exists(path))
                    {
                        File.Delete(path);
                    }

                    PicturesData.Pictures.DeleteOnSubmit(picture);
                }
                catch (Exception ex)
                {
                    ErrorContext.Add("Fail to delete pictures", ex.Message);
                }
                finally
                {
                    Save();
                }
            }

            return(true);
        }
Пример #17
0
        public override void DataBind()
        {
            if (_bound)
            {
                return;
            }
            _bound = true;
            DataRow memberRow = DataBinder.Eval(this.NamingContainer, "DataItem") as DataRow;

            if (memberRow == null)
            {
                DataRowView memberRowView = DataBinder.Eval(this.NamingContainer, "DataItem") as DataRowView;
                if (memberRowView != null)
                {
                    memberRow = memberRowView.Row;
                }
            }
            if (memberRow == null)
            {
                return;
            }

            int privacy = (int)memberRow["Privacy"];

            if (memberRow == null)
            {
                DataRowView drv = DataBinder.Eval(this.NamingContainer, "DataItem") as DataRowView;
                if (drv == null)
                {
                    ErrorContext.Add("invalid-dataitem", "Invalid Container for: " + Property);
                    this.Visible = false;
                    return;
                }
                memberRow = drv.Row;
            }
            object obj = null;

            if (memberRow.Table.Columns.Contains(Property))
            {
                obj = memberRow[Property];
            }

            PrivacySettingsManager psMgr = new PrivacySettingsManager();

            this.Visible = psMgr.CanAccess(memberRow, Property, this);

            if (!this.Visible)
            {
                return;
            }

            int MemberId = (int)memberRow["MemberId"];

            switch (Property)
            {
            /*case "Network":
             *      MemberNetworksManager nMgr = new MemberNetworksManager();
             *      IQueryable<MemberNetworksView> networks = nMgr.GetMemberNetworksView((int)memberRow["MemberId"]);
             *      if (networks.Count() > 0)
             *      {
             *              obj = networks.First().Name;
             *      }
             *      break;
             */
            case "Gender":
                if (memberRow["Gender"] != DBNull.Value && memberRow["Gender"] != null)
                {
                    Gender gender = (Gender)Enum.Parse(typeof(Gender), memberRow["Gender"].ToString());
                    obj = gender.ToString();
                }
                break;

            case "Email":
                break;

            case "StudentID":
                if (MemberId != WebContext.Profile.UserId)
                {
                    this.Visible = false;
                }
                break;

            default:
                break;
            }

            if (obj != null && obj.ToString().Trim() != "")
            {
                obj = string.Format(Format, obj);

                this.Text = StringUtils.AddSup(obj.ToString());
            }
            base.DataBind();

            _iVisible = this.Visible && !String.IsNullOrWhiteSpace(this.Text);
        }
Пример #18
0
        public Network UpdateNetwork(int network, string title, int?status, DateTime date, string description, int parentId, int operatorId,
                                     string website, string xmlField, int largeWidth, int largeHeight, int thumbWidth,
                                     int thumbHeight, int mediumWidth, int mediumHeight, bool DeleteImage, HttpPostedFile Image)
        {
            var n = GetNetwork(network);

            if (xmlField == null || xmlField == "")
            {
                xmlField = "<xml />";
            }
            n.Name         = title;
            n.Description  = description;
            n.ParentId     = parentId;
            n.OperatorId   = operatorId;
            n.Website      = website;
            n.XmlField     = System.Xml.Linq.XElement.Parse(xmlField);
            n.LastModified = DateTime.Now;
            n.Status       = status;

            NetworkData.SubmitChanges();

            string path = WebContext.Server.MapPath("~/" + lw.CTE.Folders.Networks);

            path = System.IO.Path.Combine(path, string.Format("Network{0}", n.NetworkId));

            string largePath    = "";
            string mediumPath   = "";
            string thumbPath    = "";
            string originalPath = "";

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);

                Directory.CreateDirectory(Path.Combine(path, "Large"));
                Directory.CreateDirectory(Path.Combine(path, "Thumb"));
                Directory.CreateDirectory(Path.Combine(path, "Medium"));
            }
            else
            {
                largePath = Path.Combine(path, "Large");
                if (!Directory.Exists(largePath))
                {
                    Directory.CreateDirectory(largePath);
                }

                thumbPath = Path.Combine(path, "Thumb");
                if (!Directory.Exists(thumbPath))
                {
                    Directory.CreateDirectory(thumbPath);
                }

                mediumPath = Path.Combine(path, "Medium");
                if (!Directory.Exists(mediumPath))
                {
                    Directory.CreateDirectory(mediumPath);
                }
            }

            bool del = (DeleteImage || (Image != null && Image.ContentLength > 0)) &&
                       n.Image != null && n.Image.ToString() != "";

            bool updateData = false;

            if (del)
            {
                originalPath = Path.Combine(path, n.Image);
                largePath    = Path.Combine(largePath, n.Image);
                mediumPath   = Path.Combine(mediumPath, n.Image);
                thumbPath    = Path.Combine(thumbPath, n.Image);

                if (File.Exists(originalPath))
                {
                    File.Delete(originalPath);
                }

                if (File.Exists(largePath))
                {
                    File.Delete(largePath);
                }

                if (File.Exists(mediumPath))
                {
                    File.Delete(mediumPath);
                }

                if (File.Exists(thumbPath))
                {
                    File.Delete(thumbPath);
                }

                n.Image    = "";
                updateData = true;
            }

            if (Image != null && Image.ContentLength > 0)
            {
                Config cfg = new Config();

                string fileName = StringUtils.GetFileName(Image.FileName);

                string ImageName       = string.Format("{0}\\{1}", path, fileName);
                string largeImageName  = string.Format("{0}\\Large/{1}", path, fileName);
                string thumbImageName  = string.Format("{0}\\Thumb/{1}", path, fileName);
                string mediumImageName = string.Format("{0}\\Medium/{1}", path, fileName);

                Image.SaveAs(ImageName);

                if (largeHeight > 0 && largeWidth > 0)
                {
                    lw.GraphicUtils.ImageUtils.CropImage(ImageName, largeImageName, largeWidth, largeHeight, ImageUtils.AnchorPosition.Default);
                }
                if (thumbHeight > 0 && thumbWidth > 0)
                {
                    lw.GraphicUtils.ImageUtils.CropImage(ImageName, thumbImageName, thumbWidth, thumbHeight, ImageUtils.AnchorPosition.Default);
                }
                if (mediumHeight > 0 && mediumWidth > 0)
                {
                    lw.GraphicUtils.ImageUtils.CropImage(ImageName, mediumImageName, mediumWidth, mediumHeight, ImageUtils.AnchorPosition.Default);
                }

                if (cfg.GetKey("NetworkImage") == "on")
                {
                    try
                    {
                        int _Width  = Int32.Parse(cfg.GetKey("NetworkImageWidth"));
                        int _Height = Int32.Parse(cfg.GetKey("NetworkImageHeight"));

                        //	ImageUtils.Resize(ImageName, ImageName, _Width, _Height);
                        lw.GraphicUtils.ImageUtils.CreateThumb(ImageName, largeImageName, _Width, _Height);

                        int Width  = Int32.Parse(cfg.GetKey("NetworkImageThumbWidth"));
                        int Height = Int32.Parse(cfg.GetKey("NetworkImageThumbHeight"));
                        lw.GraphicUtils.ImageUtils.CropImage(ImageName, thumbImageName, Width, Height, ImageUtils.AnchorPosition.Default);
                        //	lw.GraphicUtils.ImageUtils.Resize(ImageName, thumbImageName, Width, Height);
                        //lw.GraphicUtils.ImageUtils.CreateThumb(ImageName, thumbImageName, Width, Height);
                        int MWidth  = Int32.Parse(cfg.GetKey("NetworkImageMediumWidth"));
                        int MHeight = Int32.Parse(cfg.GetKey("NetworkImageMediumHeight"));
                        lw.GraphicUtils.ImageUtils.CropImage(ImageName, mediumImageName, MWidth, MHeight, ImageUtils.AnchorPosition.Default);
                    }
                    catch (Exception ex)
                    {
                        ErrorContext.Add("resize-image", "Unable to resize album image.<br><span class=hid>" + ex.Message + "</span>");
                    }
                }

                n.Image    = fileName;
                updateData = true;
            }

            if (updateData)
            {
                NetworkData.SubmitChanges();
            }

            return(n);
        }
Пример #19
0
        public int AddNews(string uniqueName, string title, string header, string content, string date,
                           int NewsType, short Language, byte Status,
                           HttpPostedFile RelatedFile,
                           HttpPostedFile DefaultImage, bool autoResizePicture, DateTime?publishDate)
        {
            NewsDs _ds = new NewsDs();

            IDataAdapter Adp = base.GetAdapter(cte.NewsAdp);

            NewsDs.NewsRow row = _ds.News.NewNewsRow();

            row.Title    = title;
            row.Header   = header;
            row.NewsText = content;
            if (date != null && date != "")
            {
                row.NewsDate = DateTime.Parse(date);
            }
            else
            {
                row.NewsDate = DateTime.Now;
            }

            if (String.IsNullOrEmpty(uniqueName))
            {
                uniqueName = StringUtils.ToURL(title);
            }

            row.NewsType     = NewsType;
            row.NewsLanguage = Language;
            row.Status       = Status;
            row.DateAdded    = DateTime.Now;
            row.DateModified = DateTime.Now;
            row.CreatorId    = WebContext.Profile.UserId;
            row.ModifierId   = WebContext.Profile.UserId;

            row.Views      = 0;
            row.Ranking    = 0;
            row.UserRating = 0;

            if (publishDate != null)
            {
                row.PublishDate = publishDate.Value;
            }
            else
            {
                row.PublishDate = DateTime.Now;
            }
            row.NewsFile    = "";
            row.ThumbImage  = "";
            row.LargeImage  = "";
            row.MediumImage = "";

            _ds.News.AddNewsRow(row);
            base.UpdateData(Adp, _ds);

            string path = WebContext.Server.MapPath("~/" + lw.CTE.Folders.NewsImages);

            path = System.IO.Path.Combine(path, string.Format("News{0}", row.NewsId));


            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            Directory.CreateDirectory(Path.Combine(path, "Original"));
            Directory.CreateDirectory(Path.Combine(path, "Large"));
            Directory.CreateDirectory(Path.Combine(path, "Thumb"));



            if (RelatedFile != null && RelatedFile.ContentLength > 0)
            {
                string ext = StringUtils.GetFileExtension(RelatedFile.FileName);

                string fileName = StringUtils.GetFriendlyFileName(RelatedFile.FileName);

                if (title.Trim() == "")
                {
                    row.Title = fileName;
                }

                path = WebContext.Server.MapPath("~/");
                path = Path.Combine(path, Folders.NewsFile);

                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }

                fileName = string.Format("{0}_{1}.{2}",
                                         fileName, row.NewsId, ext);

                try
                {
                    RelatedFile.SaveAs(Path.Combine(path, fileName));
                }
                catch (IOException ex)
                {
                    throw new Exception("IO ERROR, Could not save related news file: " + ex.Message);
                }
                catch (Exception ex1)
                {
                    throw ex1;
                }
                row.NewsFile = fileName;
                base.UpdateData(Adp, _ds);
            }

            try
            {
                string sql = string.Format("Update News set UniqueName=N'{0}' where NewsId={1}",
                                           uniqueName, row.NewsId);
                DBUtils.ExecuteQuery(sql, cte.lib);
            }
            catch (Exception Ex)
            {
                ErrorContext.Add("unique-name", "cannot update unique name. " + Ex.Message);
            }
            if (DefaultImage != null && DefaultImage.ContentLength > 0)
            {
                UpdateDefaultImage(row.NewsId, NewsType, DefaultImage, autoResizePicture, false, uniqueName);
            }

            // search need to be checked for the path cannot be value null

            ///		Search.NewsSearch.AddToIndex(row.NewsId);

            return(row.NewsId);
        }
Пример #20
0
        public bool UpdateNews(int newsId, string uniqueName, string title, string header, string content, string date,
                               int NewsType, short Language, byte Status, bool DeleteFile,
                               HttpPostedFile RelatedFile,
                               HttpPostedFile DefaultImage, bool autoResizePicture, bool deleteOldPicture,
                               int?Ranking, int?UserRating, int?Views, DateTime?publishDate)
        {
            NewsDs _ds = new NewsDs();

            DataRow news = this.GetNews(string.Format("NewsId={0}", newsId))[0].Row;

            string oldImage = NewsPicture(newsId);

            IDataAdapter Adp = base.GetAdapter(cte.NewsAdp);

            NewsDs.NewsRow row = _ds.News.NewNewsRow();

            row.NewsId = newsId;
            _ds.News.AddNewsRow(row);
            row.AcceptChanges();

            row.Title = title;

            if (String.IsNullOrEmpty(uniqueName) || (uniqueName == news["UniqueName"].ToString() && uniqueName == StringUtils.ToURL(news["Title"].ToString())))
            {
                uniqueName = StringUtils.ToURL(title);
            }

            row.UniqueName = uniqueName;
            row.Header     = header;
            row.NewsText   = content;
            if (date != null && date != "")
            {
                row.NewsDate = DateTime.Parse(date);
            }

            row.NewsType     = NewsType;
            row.NewsLanguage = Language;
            row.Status       = Status;
            row.NewsFile     = string.Format("{0}", news["NewsFile"]);
            row.DateModified = DateTime.Now;
            row.ModifierId   = WebContext.Profile.UserId;

            if (Ranking != null)
            {
                row.Ranking = Ranking.Value;
            }
            if (UserRating != null)
            {
                row.UserRating = UserRating.Value;
            }
            if (Views != null)
            {
                row.Views = Views.Value;
            }
            if (publishDate != null)
            {
                row.PublishDate = publishDate.Value;
            }

            base.UpdateData(Adp, _ds);

            string path = "";

            try
            {
                if (!StringUtils.IsNullOrWhiteSpace(oldImage) && title != news["Title"].ToString())
                {
                    path = WebContext.Server.MapPath("~/" + lw.CTE.Folders.NewsImages);

                    path = System.IO.Path.Combine(path, string.Format("News{0}", newsId));

                    path = Path.Combine(path, StringUtils.ToURL(title) + ".JPG");

                    File.Move(WebContext.Server.MapPath(oldImage), path);
                }
            }
            catch (Exception Ex)
            {
                ErrorContext.Add("default-picture", "Could not re-copy default picture. " + Ex.Message);
            }

            path = WebContext.Server.MapPath("~/");
            path = Path.Combine(path, Folders.NewsFile);

            DeleteFile = (DeleteFile || (RelatedFile != null && RelatedFile.ContentLength > 0)) &&
                         !StringUtils.IsNullOrWhiteSpace(news["NewsFile"]);

            if (DeleteFile)
            {
                string fileName = Path.Combine(path, news["NewsFile"].ToString());
                if (File.Exists(fileName))
                {
                    File.Delete(fileName);
                }

                row.NewsFile = "";
            }

            if (RelatedFile != null && RelatedFile.ContentLength > 0)
            {
                string ext = StringUtils.GetFileExtension(RelatedFile.FileName);

                string fileName = StringUtils.GetFriendlyFileName(RelatedFile.FileName);

                if (title.Trim() == "")
                {
                    row.Title = fileName;
                }

                fileName = string.Format("{0}_{1}.{2}",
                                         fileName, row.NewsId, ext);

                try
                {
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }
                    RelatedFile.SaveAs(Path.Combine(path, fileName));
                }
                catch (IOException ex)
                {
                    throw new Exception("IO ERROR, Could not save related news file: " + ex.Message);
                }
                catch (Exception ex1)
                {
                    throw ex1;
                }
                row.NewsFile = fileName;
            }

            if (row.NewsFile != string.Format("{0}", news["NewsFile"]))
            {
                base.UpdateData(Adp, _ds);
            }

            try
            {
                string sql = string.Format("Update News set UniqueName=N'{0}' where NewsId={1}",
                                           uniqueName, row.NewsId);
                DBUtils.ExecuteQuery(sql, cte.lib);
            }
            catch (Exception Ex)
            {
                ErrorContext.Add("unique-name", "cannot update unique name. " + Ex.Message);
            }

            if ((DefaultImage != null && DefaultImage.ContentLength > 0) || deleteOldPicture)
            {
                UpdateDefaultImage(row.NewsId, NewsType, DefaultImage, autoResizePicture, deleteOldPicture, row.UniqueName);
            }

            //Search.NewsSearch.UpdateIndex(row.NewsId);

            return(true);
        }
Пример #21
0
        /// <summary>
        /// Creates the data
        /// </summary>
        void getData()
        {
            if (DataSrc == null)
            {
                if (!Visible)
                {
                    DataSrc = new EmptyDataSrc();
                }
                else
                {
                    // Connects to the database
                    if (data == null)
                    {
                        if (!String.IsNullOrWhiteSpace(SelectCommand))
                        {
                            if (enablePaging)
                            {
                                dataSrc = new PagingDataSource(selectCommand, _Page, OrderBy, DataLibrary);
                                ((PagingDataSource)dataSrc).PageSize = PageSize;
                            }
                            else
                            {
                                dataSrc = new DataSource(selectCommand, OrderBy, DataLibrary);
                            }
                            try
                            {
                                data = dataSrc.GetData();
                            }
                            catch (Exception ex)
                            {
                                ErrorContext.Add("CustomDataSource", ex);
                                ErrorContext.Add("CustomDataSource-Select", SelectCommand);
                            }
                            checkEmptyValue((DataTable)data);
                        }
                    }

                    // Use Config files
                    if (data == null)
                    {
                        if (!String.IsNullOrWhiteSpace(configFile))
                        {
                            DataSet ds = XmlManager.GetDataSet(configFile);
                            if (ds != null && ds.Tables.Count > 0)
                            {
                                if (!String.IsNullOrWhiteSpace(configTable))
                                {
                                    data = ds.Tables[configTable];
                                }
                                else
                                {
                                    data = ds.Tables[0];
                                }



                                if (!String.IsNullOrEmpty(OrderBy))
                                {
                                    data = new DataView((DataTable)data, "", OrderBy, DataViewRowState.CurrentRows);
                                    checkEmptyValue((DataView)data);
                                }
                                else
                                {
                                    checkEmptyValue((DataTable)data);
                                }
                            }
                        }
                    }

                    // Use an enum type
                    if (data == null)
                    {
                        if (!String.IsNullOrWhiteSpace(enumType))
                        {
                            string[] temp = enumType.Split(',');

                            Assembly    assem  = Assembly.Load(temp[1]);
                            Type        typ    = assem.GetType(temp[0]);
                            FieldInfo[] fields = typ.GetFields();

                            DataTable table = new DataTable();
                            table.Columns.Add("Value");
                            table.Columns.Add("Name");
                            table.Columns.Add("NameAttribute");
                            table.Columns.Add("DescriptionAttribute");
                            table.Columns.Add("PermissionGroupAttribute");

                            checkEmptyValue(table);

                            foreach (var field in fields)
                            {
                                if (field.Name.Equals("value__"))
                                {
                                    continue;
                                }

                                DataRow row = table.NewRow();
                                row["Value"]                    = field.GetRawConstantValue();
                                row["Name"]                     = field.Name;
                                row["NameAttribute"]            = EnumHelper.GetName((Enum)Enum.Parse(typ, field.Name));
                                row["DescriptionAttribute"]     = EnumHelper.GetDescription((Enum)Enum.Parse(typ, field.Name));
                                row["PermissionGroupAttribute"] = EnumHelper.GetPermissionGroup((Enum)Enum.Parse(typ, field.Name));
                                table.Rows.Add(row);
                            }
                            data = table;
                        }
                    }

                    // Use Direct string input 1,2,3
                    if (data == null)
                    {
                        if (!String.IsNullOrWhiteSpace(dataString))
                        {
                            string[]  temp  = dataString.Split(new Char[] { ',', ';', '|', '`' });
                            DataTable table = new DataTable();
                            table.Columns.Add("Value");
                            table.Columns.Add("Name");

                            checkEmptyValue(table);

                            if (!String.IsNullOrWhiteSpace(DataStringValues))
                            {
                                string[] valuesTemp = DataStringValues.Split(new char[] { ',', ';', '-', '`' });

                                try
                                {
                                    if (valuesTemp.Length != temp.Length)
                                    {
                                        throw new Exception("DataString and DataStringValues must have equal amount of values");
                                    }
                                    else
                                    {
                                        for (int i = 0; i < temp.Length; i++)
                                        {
                                            DataRow row = table.NewRow();
                                            row["Value"] = valuesTemp[i];
                                            row["Name"]  = temp[i];
                                            table.Rows.Add(row);

                                            data = table;
                                        }
                                    }
                                }
                                catch (Exception ex)
                                {
                                    ErrorContext.Add("CustomDataSource", ex.Message);
                                }
                            }
                            else
                            {
                                foreach (string str in temp)
                                {
                                    DataRow row = table.NewRow();
                                    row["Value"] = str;
                                    row["Name"]  = str;
                                    table.Rows.Add(row);

                                    data = table;
                                }
                            }
                        }
                    }

                    if (dataSrc == null && data != null)
                    {
                        EmptyDataSrc tempSrc = new EmptyDataSrc();
                        tempSrc.Data = data;
                        if (data != null)
                        {
                            if (data as DataView != null)
                            {
                                tempSrc.RowsCount = ((DataView)data).Table.Rows.Count;
                            }
                            else
                            {
                                tempSrc.RowsCount = ((DataTable)data).Rows.Count;
                            }
                            tempSrc.HasData = tempSrc.RowsCount > 0;
                        }
                        dataSrc = tempSrc;
                    }
                }
            }
            else
            {
                data = DataSrc.Data;
            }
        }
Пример #22
0
        public bool UpdateAlbum(int AlbumId, string Name, string DisplayName,
                                string Description,
                                bool status, int Sort,
                                bool HasIntroPage, int CategoryId,
                                bool DeleteImage, HttpPostedFile Image, Languages lan, DateTime?AlbumDate)
        {
            AlbumsDS _ds = new AlbumsDS();

            AlbumsDSTableAdapters.PhotoAlbumsTableAdapter adp = new AlbumsDSTableAdapters.PhotoAlbumsTableAdapter();

            DataRow album = this.GetPhotoAlbums(string.Format("Id={0}", AlbumId))[0].Row;

            album["Name"]         = StringUtils.ToURL(DisplayName);
            album["DisplayName"]  = DisplayName;
            album["Description"]  = Description;
            album["Status"]       = status;
            album["Sort"]         = Sort;
            album["HasIntroPage"] = HasIntroPage;
            album["CategoryId"]   = CategoryId;
            album["DateAdded"]    = (DateTime)album["DateAdded"];
            album["DateModified"] = DateTime.Now;
            album["Image"]        = album["Image"].ToString();
            album["Language"]     = (short)lan;
            if (AlbumDate != null)
            {
                album["AlbumDate"] = AlbumDate.Value;
            }

            adp.Update(album);


            string path = WebContext.Server.MapPath("~/" + lw.CTE.Folders.PhotoAlbums);

            path = System.IO.Path.Combine(path, string.Format("Album{0}", album["Id"]));

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);

                Directory.CreateDirectory(Path.Combine(path, "Original"));
                Directory.CreateDirectory(Path.Combine(path, "Large"));
                Directory.CreateDirectory(Path.Combine(path, "Thumb"));
            }


            bool del = (DeleteImage || (Image != null && Image.ContentLength > 0)) &&
                       album["Image"].ToString() != "";

            bool updateData = false;

            if (DeleteImage)
            {
                string fileName = Path.Combine(path, album["Image"].ToString());
                if (File.Exists(fileName))
                {
                    File.Delete(fileName);
                }


                fileName = Path.Combine(path, "Large_" + album["Image"].ToString());
                if (File.Exists(fileName))
                {
                    File.Delete(fileName);
                }

                fileName = Path.Combine(path, "Thumb_" + album["Image"].ToString());
                if (File.Exists(fileName))
                {
                    File.Delete(fileName);
                }

                album["Image"] = "";
                updateData     = true;
            }

            //if (!DeleteImage && Image != null && Image.ContentLength > 0)
            if (Image != null && Image.ContentLength > 0)
            {
                Config cfg = new Config();

                string fileName = StringUtils.GetFileName(Image.FileName);

                string ImageName      = string.Format("{0}\\{1}", path, fileName);
                string largeImageName = string.Format("{0}\\Large_{1}", path, fileName);
                string thumbImageName = string.Format("{0}\\Thumb_{1}", path, fileName);

                Image.SaveAs(ImageName);

                if (cfg.GetKey("AlbumImage") == "on")
                {
                    try
                    {
                        Dimension largeImageSize = new Dimension(cte.CoverPhotoDefaultSize);
                        Dimension thumbImageSize = new Dimension(cte.CoverPhotoDefaultThumbSize);

                        if (!string.IsNullOrWhiteSpace(cfg.GetKey(cte.CoverPhotoSize)))
                        {
                            largeImageSize = new Dimension(cfg.GetKey(cte.CoverPhotoSize));
                        }
                        if (!string.IsNullOrWhiteSpace(cfg.GetKey(cte.CoverPhotoThumbSize)))
                        {
                            thumbImageSize = new Dimension(cfg.GetKey(cte.CoverPhotoThumbSize));
                        }

                        lw.GraphicUtils.ImageUtils.Resize(ImageName, largeImageName, largeImageSize.IntWidth, largeImageSize.IntHeight);
                        lw.GraphicUtils.ImageUtils.CropImage(ImageName, thumbImageName, thumbImageSize.IntWidth, thumbImageSize.IntHeight, ImageUtils.AnchorPosition.Default);
                    }
                    catch (Exception ex)
                    {
                        ErrorContext.Add("resize-image", "Unable to resize album image.<br><span class=hid>" + ex.Message + "</span>");
                    }
                }

                album["Image"] = fileName;
                updateData     = true;
            }

            if (updateData)
            {
                adp.Update(album);
            }

            return(true);
        }
Пример #23
0
        public override void DataBind()
        {
            dataSrc = this.Parent as CommentsDataSource;

            if (!_bound)
            {
                _bound = true;

                CommentsManager cMgr = new CommentsManager();

                Comments.Comments_Tables_View table = cMgr.GetTableDetails(TableName);
                if (table == null)
                {
                    CommentsSetup cs = new CommentsSetup();
                    if (MembersOnly)
                    {
                        cs.CreateCommentsTableWithMembers(TableName, RelateTo, 1);
                    }
                    else
                    {
                        cs.CreateCommentsTableNoMembers(TableName, RelateTo, 1);
                    }

                    table = cMgr.GetTableDetails(TableName);
                }

                //HtmlInputHidden RelationId = new HtmlInputHidden();
                //RelationId.ID = "RelationId";
                //RelationId.Value = "-2";
                //this.Controls.Add(RelationId);

                HtmlInputHidden ParentId = new HtmlInputHidden();
                ParentId.ID = "ParentId";
                if (this.dataSrc == null)
                {
                    ParentId.Value = "-1";
                }
                else
                {
                    ParentId.Value = dataSrc.ParentId.ToString();
                }
                this.Controls.Add(ParentId);


                if (!NoRelations)
                {
                    object relationValue = ControlUtils.GetBoundedDataField(this.NamingContainer, table.RelationField);

                    RelationId = (int)relationValue;
                }
                if (AjaxSubmit)
                {
                    AjaxResponse resp = new AjaxResponse();

                    if (this.IsPostBack)
                    {
                        resp.callBack = this.AjaxCallback;
                        this.Validate();
                        resp.valid = this.IsValid.Value;

                        if (resp.valid)
                        {
                            if (this.MembersOnly)
                            {
                                string text = WebContext.Request["CommentText"];
                                if (!String.IsNullOrWhiteSpace(text))
                                {
                                    int comment = cMgr.AddMemberComment(TableName,
                                                                        Int32.Parse(ParentId.Value), RelationId,
                                                                        WebContext.Request["CommentTitle"],
                                                                        text, WebContext.Profile.UserId, CommentType.Text);

                                    var dr = cMgr.GetTopComment(TableName, RelationId, Int32.Parse(ParentId.Value), "Order By CommentId Desc");

                                    MembersManager mMgr = new MembersManager();

                                    resp r = new resp();

                                    string mId = dr["MemberId"].ToString();

                                    if (!String.IsNullOrWhiteSpace(mId))
                                    {
                                        var member = mMgr.GetMember(Int32.Parse(mId));

                                        r.FirstName = member.FirstName;
                                        r.LastName  = member.LastName;
                                        r.Username  = member.UserName;
                                        r.Picture   = member.Picture;
                                    }

                                    r.CommentId   = dr["CommentId"].ToString();
                                    r.ParentId    = dr["ParentId"].ToString();
                                    r.RelationId  = dr["RelationId"].ToString();
                                    r.DateCreated = string.Format("{0:MMM dd, yyyy} at {0:h:mm:tt}", dr["DateCreated"]);
                                    r.Title       = dr["Title"].ToString();
                                    r.CommentText = dr["CommentText"].ToString();
                                    r.MemberId    = dr["MemberId"].ToString();
                                    r.TableName   = TableName;

                                    resp.data    = r;
                                    resp.message = "Text successfully added";
                                    resp.error   = null;
                                }
                                else
                                {
                                    resp.message = "Please write your text before submitting and try again.";
                                    resp.error   = "true";
                                }
                            }
                            else
                            {
                                NameValueCollection post = GetValues();
                                ContentManager      pMgr = new ContentManager();

                                CustomPage thisPage = this.Page as CustomPage;
                                if (thisPage == null)
                                {
                                    thisPage = new CustomPage();
                                }

                                if (String.IsNullOrEmpty(post["Name"]))
                                {
                                    Validated = false;
                                    ErrorContext.Add("validation-name", ContentManager.ErrorMsg("Name-Validation", thisPage.Language));
                                }
                                if (String.IsNullOrEmpty(post["Email"]) || !Validation.IsEmail(post["Email"]))
                                {
                                    Validated = false;
                                    ErrorContext.Add("validation-email", ContentManager.ErrorMsg("Email-Validation", thisPage.Language));
                                }
                                if (String.IsNullOrEmpty(post["Title"]))
                                {
                                    Validated = false;
                                    ErrorContext.Add("validation-comment", ContentManager.ErrorMsg("Comment-Validation", thisPage.Language));
                                }
                                if (String.IsNullOrEmpty(post["Comment"]))
                                {
                                    Validated = false;
                                    ErrorContext.Add("validation-comment", ContentManager.ErrorMsg("Comment-Validation", thisPage.Language));
                                }
                                if (Validated != null && Validated.Value)
                                {
                                    int commentId = -1;
                                    try
                                    {
                                        commentId = cMgr.AddNoMemberComment(TableName, -1,
                                                                            RelationId,
                                                                            post["Title"],
                                                                            post["Comment"], WebContext.Profile.UserGuid,
                                                                            post["Name"], post["Website"],
                                                                            post["Country"], WebContext.Request.ServerVariables["REMOTE_ADDR"],
                                                                            post["avatar"], CommentType.Text);
                                    }
                                    catch (Exception ex)
                                    {
                                        ErrorContext.Add(ex);
                                    }
                                    if (commentId > 0)
                                    {
                                        if (!String.IsNullOrEmpty(table.Email))
                                        {
                                            Config cfg  = new Config();
                                            Mail   mail = new Mail("Comments");
                                            mail.Subject = post["Name"] + " submitted a comment to " + table.TableName;

                                            NameValueCollection dic = new NameValueCollection();
                                            dic["Name"]    = post["Name"];
                                            dic["Email"]   = post["Email"];
                                            dic["Comment"] = StringUtils.PutBR(post["Comment"].ToString());

                                            if (!String.IsNullOrWhiteSpace(post["Website"]))
                                            {
                                                dic["Website"] = post["Website"];
                                            }

                                            ArrayList files = cMgr.AddFiles(TableName, commentId);

                                            StringBuilder sb = new StringBuilder();

                                            if (files.Count > 0)
                                            {
                                                sb.Append("<dl><dt>Files:</dt><dd>");
                                                foreach (string s in files)
                                                {
                                                    string temp = s;
                                                    if (temp.IndexOf("~") == 0)
                                                    {
                                                        temp = temp.Substring(1);
                                                    }

                                                    sb.Append(String.Format("<a href=\"http://{0}/{1}\">{2}</a>",
                                                                            WebTools.WebContext.ServerName,
                                                                            s.Replace("\\", "/").Substring(1),
                                                                            Path.GetFileName(temp)));
                                                    sb.Append("<br />");
                                                }
                                                sb.Append("</dd></dl>");
                                            }

                                            dic["Files"] = sb.ToString();
                                            sb.Clear();

                                            sb.Append(string.Format(@"<p>
	<a href=""http://{0}/Prv/proxies/comments/status.ashx?commentId={1}&table={2}&action=approve"">Approve</a>
	- <a href=""http://{0}/Prv/proxies/comments/status.ashx?commentId={1}&table={2}&action=edit"">Edit</a>
	- <a href=""http://{0}/Prv/proxies/comments/status.ashx?CommentId={1}&table={2}&action=delete"">Delete</a>
</p>", WebTools.WebContext.ServerName, commentId, table.TableName));

                                            dic["Permission"] = sb.ToString();

                                            mail.Data = dic;
                                            mail.To   = table.Email;

                                            /*
                                             * mail.From = cfg.GetKey("EmailsFrom");
                                             *
                                             * StringBuilder sb = new StringBuilder();
                                             *
                                             * sb.Append("<dl>");
                                             * sb.Append(String.Format("<dt>Name: </dt><dd>{0}</dd>", post["Name"]));
                                             * sb.Append(String.Format("<dt>Email: </dt><dd>{0}</dd>", post["Email"]));
                                             *
                                             * if(!String.IsNullOrWhiteSpace(post["Website"]))
                                             *      sb.Append(String.Format("<dt>Website: </dt><dd>{0}</dd>", post["Website"]));
                                             *
                                             *
                                             * ArrayList files = cMgr.AddFiles(TableName, commentId);
                                             *
                                             * if (files.Count > 0)
                                             * {
                                             *      sb.Append("<dt>Files:</dt><dd>");
                                             *      foreach (string s in files)
                                             *      {
                                             *              String.Format("<a href=\"{0}/{1}\">{2}</a>",
                                             *                      WebTools.WebContext.ServerName,
                                             *                      s.Replace("\\", "/"),
                                             *                      Path.GetFileName(s));
                                             *      }
                                             *      sb.Append("</dd>");
                                             * }
                                             *
                                             * sb.Append(String.Format("<dt>Comment: </dt><dd>{0}</dd>", StringUtils.PutBR(post["Comment"])));
                                             * sb.Append("</dl>");
                                             *
                                             * sb.Append(string.Format(@"<p>
                                             * <a href=""http://{0}/Prv/proxies/comments/status.ashx?commentId={1}&table={2}&action=approve"">Approve</a>
                                             * - <a href=""http://{0}/Prv/proxies/comments/status.ashx?commentId={1}&table={2}&action=edit"">Edit</a>
                                             * - <a href=""http://{0}/Prv/proxies/comments/status.ashx?CommentId={1}&table={2}&action=delete"">Delete</a>
                                             * </p>", WebTools.WebContext.ServerName, commentId, table.TableName));
                                             *
                                             * mail.Body = sb.ToString();
                                             * mail.Subject = post["Name"] + " submitted a comment to " + table.TableName;
                                             */
                                            mail.Send();
                                        }
                                        SuccessContext.Add("comment-submitted", ContentManager.Message("comment-submitted"));
                                        this.Visible = false;
                                    }
                                }
                            }
                        }
                        resp.WriteJson(true);
                    }
                }
                else
                {
                    if (this.MembersOnly)
                    {
                        string text = WebContext.Request["CommentText"];
                        if (!String.IsNullOrWhiteSpace(text))
                        {
                            cMgr.AddMemberComment(TableName,
                                                  Int32.Parse(ParentId.Value), RelationId,
                                                  WebContext.Request["CommentTitle"],
                                                  text, WebContext.Profile.UserId, CommentType.Text);

                            WebContext.Response.Redirect(WebContext.Request.RawUrl);
                        }
                    }
                    else
                    {
                        NameValueCollection post = GetValues();
                        ContentManager      pMgr = new ContentManager();

                        CustomPage thisPage = this.Page as CustomPage;
                        if (thisPage == null)
                        {
                            thisPage = new CustomPage();
                        }

                        if (String.IsNullOrEmpty(post["Name"]))
                        {
                            Validated = false;
                            ErrorContext.Add("validation-name", ContentManager.ErrorMsg("Name-Validation", thisPage.Language));
                        }
                        if (String.IsNullOrEmpty(post["Email"]) || !Validation.IsEmail(post["Email"]))
                        {
                            Validated = false;
                            ErrorContext.Add("validation-email", ContentManager.ErrorMsg("Email-Validation", thisPage.Language));
                        }
                        if (String.IsNullOrEmpty(post["Title"]))
                        {
                            Validated = false;
                            ErrorContext.Add("validation-comment", ContentManager.ErrorMsg("Comment-Validation", thisPage.Language));
                        }
                        if (String.IsNullOrEmpty(post["Comment"]))
                        {
                            Validated = false;
                            ErrorContext.Add("validation-comment", ContentManager.ErrorMsg("Comment-Validation", thisPage.Language));
                        }
                        if (Validated != null && Validated.Value)
                        {
                            int commentId = -1;
                            try
                            {
                                commentId = cMgr.AddNoMemberComment(TableName, -1,
                                                                    RelationId,
                                                                    post["Title"],
                                                                    post["Comment"], WebContext.Profile.UserGuid,
                                                                    post["Name"], post["Website"],
                                                                    post["Country"], WebContext.Request.ServerVariables["REMOTE_ADDR"],
                                                                    post["avatar"], CommentType.Text);
                            }
                            catch (Exception ex)
                            {
                                ErrorContext.Add(ex);
                            }
                            if (commentId > 0)
                            {
                                if (!String.IsNullOrEmpty(table.Email))
                                {
                                    Config cfg  = new Config();
                                    Mail   mail = new Mail("Comments");
                                    mail.Subject = post["Name"] + " submitted a comment to " + table.TableName;

                                    NameValueCollection dic = new NameValueCollection();
                                    dic["Name"]    = post["Name"];
                                    dic["Email"]   = post["Email"];
                                    dic["Comment"] = StringUtils.PutBR(post["Comment"].ToString());

                                    if (!String.IsNullOrWhiteSpace(post["Website"]))
                                    {
                                        dic["Website"] = post["Website"];
                                    }

                                    ArrayList files = cMgr.AddFiles(TableName, commentId);

                                    StringBuilder sb = new StringBuilder();

                                    if (files.Count > 0)
                                    {
                                        sb.Append("<dl><dt>Files:</dt><dd>");
                                        foreach (string s in files)
                                        {
                                            string temp = s;
                                            if (temp.IndexOf("~") == 0)
                                            {
                                                temp = temp.Substring(1);
                                            }

                                            sb.Append(String.Format("<a href=\"http://{0}/{1}\">{2}</a>",
                                                                    WebTools.WebContext.ServerName,
                                                                    s.Replace("\\", "/").Substring(1),
                                                                    Path.GetFileName(temp)));
                                            sb.Append("<br />");
                                        }
                                        sb.Append("</dd></dl>");
                                    }

                                    dic["Files"] = sb.ToString();
                                    sb.Clear();

                                    sb.Append(string.Format(@"<p>
								<a href=""http://{0}/Prv/proxies/comments/status.ashx?commentId={1}&table={2}&action=approve"">Approve</a>
								- <a href=""http://{0}/Prv/proxies/comments/status.ashx?commentId={1}&table={2}&action=edit"">Edit</a>
								- <a href=""http://{0}/Prv/proxies/comments/status.ashx?CommentId={1}&table={2}&action=delete"">Delete</a>
							</p>"                            , WebTools.WebContext.ServerName, commentId, table.TableName));

                                    dic["Permission"] = sb.ToString();

                                    mail.Data = dic;
                                    mail.To   = table.Email;

                                    /*
                                     * mail.From = cfg.GetKey("EmailsFrom");
                                     *
                                     * StringBuilder sb = new StringBuilder();
                                     *
                                     * sb.Append("<dl>");
                                     * sb.Append(String.Format("<dt>Name: </dt><dd>{0}</dd>", post["Name"]));
                                     * sb.Append(String.Format("<dt>Email: </dt><dd>{0}</dd>", post["Email"]));
                                     *
                                     * if(!String.IsNullOrWhiteSpace(post["Website"]))
                                     *      sb.Append(String.Format("<dt>Website: </dt><dd>{0}</dd>", post["Website"]));
                                     *
                                     *
                                     * ArrayList files = cMgr.AddFiles(TableName, commentId);
                                     *
                                     * if (files.Count > 0)
                                     * {
                                     *      sb.Append("<dt>Files:</dt><dd>");
                                     *      foreach (string s in files)
                                     *      {
                                     *              String.Format("<a href=\"{0}/{1}\">{2}</a>",
                                     *                      WebTools.WebContext.ServerName,
                                     *                      s.Replace("\\", "/"),
                                     *                      Path.GetFileName(s));
                                     *      }
                                     *      sb.Append("</dd>");
                                     * }
                                     *
                                     * sb.Append(String.Format("<dt>Comment: </dt><dd>{0}</dd>", StringUtils.PutBR(post["Comment"])));
                                     * sb.Append("</dl>");
                                     *
                                     * sb.Append(string.Format(@"<p>
                                     * <a href=""http://{0}/Prv/proxies/comments/status.ashx?commentId={1}&table={2}&action=approve"">Approve</a>
                                     * - <a href=""http://{0}/Prv/proxies/comments/status.ashx?commentId={1}&table={2}&action=edit"">Edit</a>
                                     * - <a href=""http://{0}/Prv/proxies/comments/status.ashx?CommentId={1}&table={2}&action=delete"">Delete</a>
                                     * </p>", WebTools.WebContext.ServerName, commentId, table.TableName));
                                     *
                                     * mail.Body = sb.ToString();
                                     * mail.Subject = post["Name"] + " submitted a comment to " + table.TableName;
                                     */
                                    mail.Send();
                                }
                                SuccessContext.Add("comment-submitted", ContentManager.Message("comment-submitted"));
                                this.Visible = false;
                            }
                        }
                    }
                }
            }
            base.DataBind();
        }
Пример #24
0
        public int AddAlbum(string Name, string DisplayName,
                            string Description,
                            bool status, int Sort,
                            bool HasIntroPage,
                            int CategoryId, HttpPostedFile Image,
                            Languages lan, DateTime?AlbumDate, bool FixedSize)
        {
            AlbumsDS _ds = new AlbumsDS();

            IDataAdapter Adp = base.GetAdapter(cte.PhotoAlbumsAdp);

            AlbumsDS.PhotoAlbumsRow row = _ds.PhotoAlbums.NewPhotoAlbumsRow();

            row.Name         = StringUtils.ToURL(DisplayName);
            row.DisplayName  = DisplayName;
            row.Description  = Description;
            row.Status       = status;
            row.Sort         = Sort;
            row.HasIntroPage = HasIntroPage;
            row.CategoryId   = CategoryId;
            row.DateAdded    = DateTime.Now;
            row.DateModified = DateTime.Now;
            row.Language     = (short)lan;

            if (AlbumDate != null)
            {
                row.AlbumDate = AlbumDate.Value;
            }

            _ds.PhotoAlbums.AddPhotoAlbumsRow(row);
            base.UpdateData(Adp, _ds);

            string path = WebContext.Server.MapPath("~/" + lw.CTE.Folders.PhotoAlbums);

            path = System.IO.Path.Combine(path, string.Format("Album{0}", row.Id));


            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            Directory.CreateDirectory(Path.Combine(path, "Large"));
            Directory.CreateDirectory(Path.Combine(path, "Thumb"));
            Directory.CreateDirectory(Path.Combine(path, "Original"));

            if (Image != null && Image.ContentLength > 0)
            {
                Config cfg = new Config();

                string fileName = StringUtils.GetFileName(Image.FileName);

                string ImageName      = string.Format("{0}\\{1}", path, fileName);
                string largeImageName = string.Format("{0}\\Large_{1}", path, fileName);
                string thumbImageName = string.Format("{0}\\Thumb_{1}", path, fileName);

                Image.SaveAs(ImageName);

                try
                {
                    Dimension largeImageSize = new Dimension(cte.CoverPhotoDefaultSize);
                    Dimension thumbImageSize = new Dimension(cte.CoverPhotoDefaultThumbSize);

                    if (!string.IsNullOrWhiteSpace(cfg.GetKey(cte.CoverPhotoSize)))
                    {
                        largeImageSize = new Dimension(cfg.GetKey(cte.CoverPhotoSize));
                    }
                    if (!string.IsNullOrWhiteSpace(cfg.GetKey(cte.CoverPhotoThumbSize)))
                    {
                        thumbImageSize = new Dimension(cfg.GetKey(cte.CoverPhotoThumbSize));
                    }


                    ////ImageUtils.Resize(ImageName, ImageName, _Width, _Height);
                    //if (FixedSize)
                    //    lw.GraphicUtils.ImageUtils.CreateThumb(ImageName, largeImageName, largeImageSize.IntWidth, largeImageSize.IntHeight, FixedSize);
                    //else
                    //    lw.GraphicUtils.ImageUtils.CreateThumb(ImageName, largeImageName, largeImageSize.IntWidth, largeImageSize.IntHeight);


                    ////TODO: add a parameter to choose between the below
                    ////lw.GraphicUtils.ImageUtils.Resize(ImageName, thumbImageName, Width, Height);
                    //lw.GraphicUtils.ImageUtils.CreateThumb(ImageName, thumbImageName, thumbImageSize.IntWidth, thumbImageSize.IntHeight, FixedSize);

                    lw.GraphicUtils.ImageUtils.Resize(ImageName, largeImageName, largeImageSize.IntWidth, largeImageSize.IntHeight);
                    lw.GraphicUtils.ImageUtils.CropImage(ImageName, thumbImageName, thumbImageSize.IntWidth, thumbImageSize.IntHeight, ImageUtils.AnchorPosition.Default);
                }
                catch (Exception ex)
                {
                    ErrorContext.Add("resize-image", "Unable to resize album image.<br><span class=hid>" + ex.Message + "</span>");
                }


                row.Image = fileName;
                base.UpdateData(Adp, _ds);
            }

            return(row.Id);
        }
Пример #25
0
        public int UpdateMember(int MemberId, string userName,
                                string password,
                                string email, string AlternateEmail,
                                string SecretQuestion, string SecretAnswer,
                                string title,
                                string firstName,
                                string middleName,
                                string lastName, Gender?gender,
                                DateTime?dateOfBirth,
                                int?status, int?ChangedBy,
                                bool?JoinNewsletter,
                                string PrivateComments, string Comments, string FullName)
        {
            /* or Email='{1}' */
            string cond = string.Format("(UserName='******' or Email='{1}') and MemberId<>{2}",
                                        StringUtils.SQLEncode(userName),
                                        StringUtils.SQLEncode(email),
                                        MemberId);

            if (GetMembers(cond).Rows.Count > 0 && email != "")
            {
                ErrorContext.Add("validation", ContentManager.ErrorMsg(Errors.UserAlreadyExists));
                return(-1);
            }
            MembersDsTableAdapters.MembersTableAdapter adp = new lw.Members.MembersDsTableAdapters.MembersTableAdapter();

            MembersDs.MembersRow member = (MembersDs.MembersRow) this.GetMember(MemberId);

            member.UserName = userName;
            member.Email    = email;

            if (!string.IsNullOrEmpty(password))
            {
                member.Password = EncryptPassword(password);
            }

            if (AlternateEmail != null)
            {
                member.AlternateEmail = AlternateEmail;
            }

            if (SecretQuestion != null)
            {
                member.SecretQuestion = SecretQuestion;
            }

            if (SecretAnswer != null)
            {
                member.SecretQuestionAnswer = SecretAnswer;
            }

            if (title != null)
            {
                member.Title = title;
            }

            if (firstName != null)
            {
                member.FirstName = firstName;
            }

            if (lastName != null)
            {
                member.LastName = lastName;
            }

            if (gender != null)
            {
                member.Gender = (short)gender;
            }

            if (dateOfBirth != null)
            {
                member.DateOfBirth = dateOfBirth.Value;
            }

            if (status != null)
            {
                member.Status = status.Value;
            }

            if (JoinNewsletter != null)
            {
                member.JoinNewsletter = JoinNewsletter.Value;
            }

            if (ChangedBy != null)
            {
                member.ChangedBy = ChangedBy.Value;
            }

            if (PrivateComments != null)
            {
                member.PrivateComments = PrivateComments;
            }

            if (Comments != null)
            {
                member.Comments = Comments;
            }

            if (middleName != null)
            {
                member.MiddleName = middleName;
            }

            member.LastModified = DateTime.Now;

            return(adp.Update(member));
        }
Пример #26
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="AlbumId"></param>
        /// <param name="Caption"></param>
        /// <param name="image"></param>
        /// <returns></returns>
        ///

        /*
         * <Parameters>
         *      <key>PhotoAlbum_Thumb_Image_Option</key>
         *      <value>Resize</value> or <value>Crop</value>
         * </Parameters>
         */

        public DataRow AddImage(int AlbumId, string Caption, string image)
        {
            AlbumsDS _ds = new AlbumsDS();

            IDataAdapter Adp = base.GetAdapter(cte.PhotoAlbumImagesAdp);

            AlbumsDS.PhotoAlbumImagesRow row = _ds.PhotoAlbumImages.NewPhotoAlbumImagesRow();

            row.AlbumId      = AlbumId;
            row.Caption      = Caption;
            row.Sort         = 100;
            row.DateAdded    = DateTime.Now;
            row.DateModified = DateTime.Now;

            _ds.PhotoAlbumImages.AddPhotoAlbumImagesRow(row);
            base.UpdateData(Adp, _ds);

            string path = WebContext.Server.MapPath("~/" + lw.CTE.Folders.PhotoAlbums);

            path = System.IO.Path.Combine(path, string.Format("Album{0}", AlbumId));
            string largePath    = Path.Combine(path, "Large");
            string thumbPath    = Path.Combine(path, "Thumb");
            string originalPath = Path.Combine(path, "Original");


            if (!Directory.Exists(largePath))
            {
                Directory.CreateDirectory(largePath);
            }

            if (!Directory.Exists(thumbPath))
            {
                Directory.CreateDirectory(thumbPath);
            }

            if (!Directory.Exists(originalPath))
            {
                Directory.CreateDirectory(originalPath);
            }

            Config cfg = new Config();

            string ext      = StringUtils.GetFileExtension(image);
            string fileName = StringUtils.GetFriendlyFileName(image);

            string _ImageName = string.Format("{0}_{1}.{2}", fileName, row.Id, ext);

            string ImageName      = string.Format("{0}\\{1}", originalPath, _ImageName);
            string largeImageName = string.Format("{0}\\{1}", largePath, _ImageName);
            string thumbImageName = string.Format("{0}\\{1}", thumbPath, _ImageName);

            if (!Directory.Exists(originalPath))
            {
                Directory.CreateDirectory(originalPath);
            }

            System.IO.File.Copy(image, ImageName);

            try
            {
                Dimension largeImageSize = new Dimension(cte.ImageDefaultSize);
                Dimension thumbImageSize = new Dimension(cte.ImageDefaultThumbSize);

                if (!string.IsNullOrWhiteSpace(cfg.GetKey(cte.ImageSize)))
                {
                    largeImageSize = new Dimension(cfg.GetKey(cte.ImageSize));
                }
                if (!string.IsNullOrWhiteSpace(cfg.GetKey(cte.ImageThumbSize)))
                {
                    thumbImageSize = new Dimension(cfg.GetKey(cte.ImageThumbSize));
                }

                lw.GraphicUtils.ImageUtils.Resize(ImageName, largeImageName, largeImageSize.IntWidth, largeImageSize.IntHeight);

                if (!string.IsNullOrWhiteSpace(cfg.GetKey(cte.ImageThumbOption)) && cfg.GetKey(cte.ImageThumbOption) == "Crop")
                {
                    lw.GraphicUtils.ImageUtils.CropImage(ImageName, thumbImageName, thumbImageSize.IntWidth, thumbImageSize.IntHeight, ImageUtils.AnchorPosition.Default);
                }
                else
                {
                    lw.GraphicUtils.ImageUtils.Resize(ImageName, thumbImageName, thumbImageSize.IntWidth, thumbImageSize.IntHeight);
                }
            }
            catch (Exception ex)
            {
                ErrorContext.Add("resize-image", "Unable to resize album image.<br><span class=hid>" + ex.Message + "</span>");
            }

            row.FileName = _ImageName;
            base.UpdateData(Adp, _ds);

            UpdateAlbumModified(AlbumId, DateTime.Now);

            return(row);
        }
Пример #27
0
        public void SendMail(
            MailAddress from,
            MailAddressCollection to,
            MailAddressCollection CC,
            MailAddressCollection BCC,
            string subject,
            bool includeSiteNameInSubject,
            string bodyHtml,
            string bodyText, ArrayList attachements
            )
        {
            Config cfg = new Config();

            MailMessage msg = new MailMessage();

            msg.From = from;

            foreach (MailAddress add in to)
            {
                msg.To.Add(add);
            }
            if (CC != null)
            {
                foreach (MailAddress add in CC)
                {
                    msg.CC.Add(add);
                }
            }
            if (BCC != null)
            {
                foreach (MailAddress add in BCC)
                {
                    msg.Bcc.Add(add);
                }
            }

            //SendAllMailsFrom used for server with custom permissions
            if (!String.IsNullOrEmpty(Config.GetFromWebConfig(lw.CTE.Email.SendAllMailsFrom)))
            {
                msg.From = new MailAddress(Config.GetFromWebConfig(lw.CTE.Email.SendAllMailsFrom), from.DisplayName);
                msg.ReplyToList.Add(from);
            }

            // ReplyToSession in case we want the reply to address to be different from the sent.
            if (WebContext.Session != null && WebContext.Session[lw.CTE.Email.ReplyToSession] != null)
            {
                if (!String.IsNullOrEmpty(WebContext.Session[lw.CTE.Email.ReplyToSession].ToString()))
                {
                    msg.ReplyToList.Add(new MailAddress(WebContext.Session[lw.CTE.Email.ReplyToSession].ToString()));
                }
            }

            msg.Subject = subject;
            if (includeSiteNameInSubject)
            {
                var siteName = cfg.GetKey("SiteName");
                if (!String.IsNullOrEmpty(siteName))
                {
                    if (subject.IndexOf(siteName) < 0)
                    {
                        msg.Subject = cfg.GetKey("SiteName") + " - " + subject;
                    }
                }
            }

            if (attachements != null && attachements.Count > 0)
            {
                for (int i = 0; i < attachements.Count; i++)
                {
                    msg.Attachments.Add(new Attachment(attachements[i].ToString()));
                }
            }

            msg.Body         = bodyHtml;
            msg.IsBodyHtml   = true;
            msg.BodyEncoding = new UTF8Encoding();

            try
            {
                bool noBcc = false;
                if (WebContext.Session != null && WebContext.Session["NoBCC"] != null)
                {
                    noBcc = true;
                }
                if (!noBcc)
                {
                    string   bcc   = cfg.GetKey("BCC");
                    string[] mails = bcc.Split(new Char[] { ',', ';', '-' });
                    foreach (string mail in mails)
                    {
                        msg.Bcc.Add(mail);
                    }
                }
            }
            catch
            {
            }
            try
            {
                //WebContext.Response.Write("message sent");
                //smtp.Send(msg);

                MailQueue.AddToQueue(msg);
            }
            catch (Exception Ex)
            {
                string trace = (from.Address + "<BR>" + to + "<BR>" + subject + "<BR>" + msg.Body + "<BR>");
                trace += Ex.Message;

                ErrorContext.Add("e-mail", "Fail to send email");
                ErrorContext.Add("trace:e-mail", trace);

                throw (Ex);
            }
            for (int i = 0; i < msg.Attachments.Count; i++)
            {
                msg.Attachments[i].Dispose();
            }
            msg.Attachments.Clear();
            msg.Dispose();
            msg = null;
        }